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 ...

Link to comment
Share on other sites

[!--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 ..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.