Jump to content


Photo

preg_match_all optimizing (not working probably)


  • Please log in to reply
2 replies to this topic

#1 hero

hero
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 March 2006 - 09:12 PM

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 :

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

thanks in advance ...



#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 05 March 2006 - 06:51 AM

Use (.*?) instead of (.*). Other than that your regex is fine. Use something like this to get your values out:
<?php
foreach ($found as $match) {
    echo $match[1] . "<br>\n";
}
?>


#3 hero

hero
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 March 2006 - 05:58 PM

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

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

thanks again ..





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users