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

הוסטס - פורום אחסון האתרים הגדול בישראל (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]; 


intercooler3819 17-01-09 14:15

אני בספק..
למען הסר ספק נריץ בנצ'מארק קטן
http://jobtalk.co.il/php.php

PHP קוד:

<?php
$url 
"http://www.aaa-cccc.biz/images/footl.jpg";
$sm microtime(true);

for(
$i 0$i 100000$i++)
{
    
$parts explode("."endexplode("/"$url) ) );
    
array_pop($parts); // Remove the file extention
    
$part implode(""$parts);
}

echo 
microtime(true) - $sm "<br>";

$sm microtime(true);

for(
$i 0$i 100000$i++)
{
    
preg_match("#/(.+)\.[a-zA-Z]+$#"$url$matches);
    
$part $matches[1];
}

echo 
microtime(true) - $sm "<br>";

?>

ובשביל מתי שאני יוריד את זה מהשרת.. 3 תוצאות:
0.85934305191
0.38126707077

0.828341960907
0.366955041885

0.839604854584
0.368497848511

צדקת..

dabi 17-01-09 20:05

אוקי עזרתם לי ממש
ביטוי אחרון כנראה שאני צריך
אני צריך את הטקסט בין
<td width="100%" colspan="4" valign="top" align="right" dir=rtl><font face="Arial" size="2">


לבין
PHP קוד:

</font

תודה רבה על העזרה שאתם נותנים פה

DvirCohen 17-01-09 22:57

יותר קל לחפש בין תגי <font> במקום בכל הTD הזה..
PHP קוד:

preg_match_all("#<font[^>]*>(.+?)</font>#i"$text$matches); 


dabi 17-01-09 23:16

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

Shon12 17-01-09 23:29

PHP קוד:

<?php
$string 
"<td width='100%' colspan='4' valign='top' align='right' dir=rtl><font face='Arial' size='5'>text</font></td>";
$string explode("<>",$string);
echo 
$string[0];
?>

יביא לך את מה שבין:
HTML קוד:

<font></font>
בהצלחה.

vadimg88 17-01-09 23:52

הקוד למעלה לא יעבוד טוב. מאחר ובטוח יהיה יותר תגים מהשורה הבודדת הזאת שהוצגה מעלה.

Shon12 17-01-09 23:56

ציטוט:

נכתב במקור על ידי vadimg88 (פרסם 693341)
הקוד למעלה לא יעבוד טוב. מאחר ובטוח יהיה יותר תגים מהשורה הבודדת הזאת שהוצגה מעלה.

לפי מה שהוא אמר הוא רוצה רק את השורה הספציפית הזו...

dabi 18-01-09 00:20

vadimg88 צודק
יש כמה שורות כאלה
לכן אני צריך במיודק מה שמופיע אחרי
<td width="100&#37;" colspan="4" valign="top" align="right" dir=rtl><font face="Arial" size="2">
עד
</font>

תודה


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

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