note 92083 added to function.preg-match-all
| From: | Eng_A_Moktar at yahoo dot com | Date: | Wed, 08 Jul 2009 05:36:16 +0000 |
| Subject: | note 92083 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158050@lists.php.net to get a copy of this message | ||
Hi, I wanna make a general pattern for example i have this string , i wanna capture the titles and
links of this topic :
<?php
$str="<td valign='top'>
<center>
<a href='redirect-5321'>
Zito, Romo combo zero
<br><br>
<img src='images/img280745.png' border='0' width='190'
height='190'></a>
</center>
<br>
</td></tr><tr>
<td valign='top'>
<center>
<a href='redirect-5322'>
NBA salary cap set at $57.7 million
<br><br>
<img src='images/img280746.png' border='0' width='190'
height='190'></a>
</center>
<br>
</td></tr><tr>";
// define start and end
$title_start = ">"; $title_end = "<br><br>";
$link_start = "<a href='"; $link_end = "'";
$code = preg_match_all("/{$title_start}(.*?){$title_end}/", $str, $result1);
$code = preg_match_all("/{$link_start}(.*?){$link_end}/", $str, $result2,
PREG_PATTERN_ORDER);
echo $result1[1][0];
echo "<br />";
echo $result2[1][0];
echo "<br />";
?>
in this example, title pattern doesn't work, because there are spaces and lines,
what i wanna say, how can i make my pattern wider and flexible, even works with tags or words ?
thanks.
----
Server IP: 87.124.35.190
Probable Submitter: 41.233.21.212 (proxied: 200.150.100.55)
----
Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php
Edit -- https://master.php.net/note/edit/92083
Del: integrated -- https://master.php.net/note/delete/92083/integrated
Del: useless -- https://master.php.net/note/delete/92083/useless
Del: bad code -- https://master.php.net/note/delete/92083/bad+code
Del: spam -- https://master.php.net/note/delete/92083/spam
Del: non-english -- https://master.php.net/note/delete/92083/non-english
Del: in docs -- https://master.php.net/note/delete/92083/in+docs
Del: other reasons-- https://master.php.net/note/delete/92083
Reject -- https://master.php.net/note/reject/92083
Search -- https://master.php.net/manage/user-notes.php