הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   עזרה ביצירת ביטוי רגולרי בבקשה (https://hosts.co.il/forums/showthread.php?t=71137)

dabi 14-01-09 15:29

עזרה ביצירת ביטוי רגולרי בבקשה
 
הקוד שלי הוא בערך ככה

PHP קוד:

<td style="width:25%; padding-right:12px; padding-left:12px;">
    <
a href="http://domain.co.il/1.html"><img src='http://domain.co.il/1.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />

<
td style="width:25%; padding-right:12px; padding-left:12px;">
    <
a href="http://domain.co.il/234.html"><img src='http://domain.co.il/1ds.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />

<
td style="width:25%; padding-right:12px; padding-left:12px;">
    <
a href="http://domain.co.il/231.html"><img src='http://domain.co.il/4c1.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br /> 

אני רוצה לקבל 2 דברים (ולהדפיס את זה כמו בטבלה)
את הקישור ואתה תמונה
עכשיו בגלל שבדף יש הרבה קישורים אז צריך ליחס לקחת את הקישור שמופיע שורה אחרי
PHP קוד:

<td style="width:25%; padding-right:12px; padding-left:12px;"

נגיד לקוד הזה התוצאה צריכה להיות
http://domain.co.il/1.html
http://domain.co.il/1.jpg
_______
http://domain.co.il/234.html
http://domain.co.il/1ds.jpg
_______
http://domain.co.il/231.html
http://domain.co.il/4c1.jpg
ממש תודה לעוזרים

vadimg88 14-01-09 15:44

אין לך תג סגירה של </td> בכל שורה?

dabi 14-01-09 15:46

יש אבל החלקים המעניינים של הקוד זה מה שהצגתי גם
אני צריך לקחת את הקישור הישיר והקישור של התמונה לאחר
<td style="width:25%; padding-right:12px; padding-left:12px;">
בין השורות האלה יש עוד טקסט כמובן
לדוגמא
PHP קוד:

<td style="width:25%; padding-right:12px; padding-left:12px;">
    <
a href="http://www.domain.coil/123.html"><img src='http://www.domain.coil/1ASD.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />
    <
div style="line-height:15px;">
        <
b><a href="http://www.domain.coil/123.html">אתר 123</a></b><br />
xxxxxxxxxxxxxx
    
</div>
</
td>
<
td style="width:25%; padding-right:12px; padding-left:12px;">
    <
a href="http://www.domain.coil/1A2C.html"><img src='http://www.domain.coil/132D.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />
    <
div style="line-height:15px;">
        <
b><a href="http://www.domain.coil/123.html">אתר 123</a></b><br />
xxxxxxxxxxxxxx
    
</div>
</
td

ו...
אם יש אתר חינמי שאפשר להציג און לין ככה שאני ישים לו כזה קוד ואני אסמן מה אני צריך זה נהדר
תודה

vadimg88 14-01-09 18:05

ביטוי לא פשוט נסה את זה:

PHP קוד:

<?php

$contents 
= <<<EOF
<td style="width:25%; padding-right:12px; padding-left:12px;">
    <a href="http://www.domain.coil/123.html"><img src='http://www.domain.coil/1ASD.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />
    <div style="line-height:15px;">
        <b><a href="foo">אתר 123</a></b><br />
xxxxxxxxxxxxxx
    </div>
</td>
<td style="width:25%; padding-right:12px; padding-left:12px;">
    <a href="http://www.domain.coil/1A2C.html"><img src='http://www.domain.coil/132D.jpg' class="small_thumb" style='width:120px;height:100px;'  /></a><br />
    <div style="line-height:15px;">
        <b><a href="http://www.domain.coil/123.html">אתר 123</a></b><br />
xxxxxxxxxxxxxx
    </div>
</td>
EOF;

preg_match_all"#<a href=['\"]([^'\"]+)['\"]><img src=['\"]([^'\"]+)['\"][^/]*/></a><br />#is"$contents$matches);

print_r($matches);


dabi 16-01-09 10:31

תודה
אני צריך עוד 2 בבקשה
מהמילה
http://www.aaa-cccc.biz/images/footl.jpg
אני רוצה לקחת את המילה
footl

ומ
http://www.aaa-cccc.biz/help-me/hi-i-am.html
לקחת את
hi-i-am

תודה =]
ועכשיו אני לומד ככה שפעם הבאה אני כבר ידע לבד אני מקווה
תודה חברים

DvirCohen 16-01-09 19:51

אפשר בלי REGEX
PHP קוד:

$parts explode("."endexplode("/""http://www.aaa-cccc.biz/images/footl.jpg") ));
$name $parts[0]; 

לא בדקתי אבל נראה לי זה יעבוד.

intercooler3819 16-01-09 21:18

ציטוט:

נכתב במקור על ידי DvirCohen (פרסם 693136)
אפשר בלי REGEX
PHP קוד:

$parts explode("."endexplode("/""http://www.aaa-cccc.biz/images/footl.jpg") ));
$name $parts[0]; 

לא בדקתי אבל נראה לי זה יעבוד.

what about filename that contains dot?

DvirCohen 16-01-09 21:24

אז משתמשים בarray_pop במקום לציין באופן ספציפי את האיבר שרוצים.
אני פשוט מנסה להימנע מביטויים רגולרים, למרות שיכול להיות שבסופו של דבר זה יהיה יותר מהיר מכל הפונקציות האלה..לא יודע

intercooler3819 16-01-09 23:13

hh you are definitely right about the speed, regex is slower than any other string functions or array operations (umm its maybe faster than recursions,etc..)

DvirCohen 17-01-09 00:34

זה שעדיף להשתמש בפונקציות "רגילות" על REGEX זה ברור, אבל יכול להיות שלפעמים כמות הפונקציות שצריך להשתמש בהם כ"כ גדולה שעדיף כבר REGEX..

נגיד, אולי במקום לעשות
PHP קוד:

$parts explode("."endexplode("/"$url) ) );
array_pop($parts); // Remove the file extention
$part implode(""$parts); 

יותר מהיר כבר לעשות
PHP קוד:

preg_match("#/(.+)\.[a-zA-Z]+$#"$url$matches);
$part $matches[1]; 



כל הזמנים הם GMT +2. הזמן כעת הוא 11:32.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ