Jump to content

Recommended Posts

I'm looking to find a a starting and ending phrase and return the text in between.

 

%\{\{items\}\}(.*?)\{\{\/items\}\}%

 

I'm looking for {{items}} and {{/items}}. Anything in between, possibly multiple lines, should be returned ($1?).

 

For some reason, it returns 0 results with the following...

 

<div id="items">

{{items}}

<div class="item">

<table>

<tr>

<td>{{item_number}}</td>

<td class="text_right">{{currency}} {{item_extension}}</td>

</tr>

<tr>

<td colspan="2">{{item_units}} at {{item_cost_per_unit}}</td>

</tr>

</table>

{{item_description}}

</div>

{{/items}}

</div>

Link to comment
https://forums.phpfreaks.com/topic/266794-poisex-regex-assistance/
Share on other sites

dot-all (a period) normally doesn't match newline characters.

 

POSIX you say? Then that means you're using the ereg family of functions. Those are deprecated; you should be using the PCRE functions.

preg_match_all('%\{\{items\}\}(.*?)\{\{/items\}\}%s', $text, $matches);

The /s flag (or in this case %s) is what tells preg_match_all() that the dot-all should include newlines.

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.