Jump to content

preg_match_all optimizing (not working probably)


hero

Recommended Posts

hi all....

i hope that someone will help me with this problem ..

i have a string with some (tags) on it ..
the tags are not html tags ...i used <:::test:::>...<:::/test:::> to easy point to the words i want later ...

the problem is ..

i would like to get the words between those tags ..
i tried the preg_match_all but it seems to get the whole string not only the words between 2 tags ..
an example about what i need :

$stris="<:::test:::>hi my name is <:::/test:::><:::test:::> Testtext <:::/test:::> and here is another <:::test>text<:::/test:::>";


the preg_match_all should return :
1 match :hi my name is
2 match :Testtext
3 match :text

please help me to get the right expression,since it is not working with me ..
here is what i have :

[code]$findwords = preg_match_all("/<:::test:::>(.*)<:::\/test:::>/", $stris, $found);[/code]

thanks in advance ...

[!--quoteo(post=351768:date=Mar 5 2006, 07:51 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 5 2006, 07:51 AM) [snapback]351768[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Use (.*?) instead of (.*). Other than that your regex is fine. Use something like this to get your values out:
[code]<?php
foreach ($found as $match) {
    echo $match[1] . "<br>\n";
}
?>[/code]
[/quote]

hi ..
thx for ur help ...it works now ..
can you please tell me what did the ? changed !?

thanks again ..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.