Jump to content

Recommended Posts

$str='....

<content:encoded>This is the embeded content</content:encoded>

...';

 

I want to get the text "This is the embeded content"

I'm using

preg_match('/<content:encoded>(.*)<\/content:encoded>/i',$str,$match); and

preg_match('/<content\:encoded>(.*)<\/content\:encoded>/i',$str,$match);

and print_r($match); but array is empty

 

Please help

 

Link to comment
https://forums.phpfreaks.com/topic/185145-preg_match-problem/
Share on other sites

In theory your first pattern is correct, it depends on the context in which it is used. Since by default the . match will be greedy you could end up matching more than you want to. If you are trying to say it's not currently working I would guess you need to add the s modifier so that the . matches \n characters.

Link to comment
https://forums.phpfreaks.com/topic/185145-preg_match-problem/#findComment-977329
Share on other sites

@sastro,

 

Just be careful about using .* as depending on the string in question, it might match more than you expected. Typically, it will match as much as it can, then backtrack to the last instance of </content:encoded> found (which may, or may not be desirable).

 

You can read up about the pitfalls of using greedy quantifiers here (post #11 and #14 in particular).

Link to comment
https://forums.phpfreaks.com/topic/185145-preg_match-problem/#findComment-977368
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.