Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Help with PHP Regex...

I am using the following regex to extract tags from text that appear in curly brackets {}. It works fine if the only text is the tag, such as {img:Src} but if there is anything else in there it doesn't work. so '{img:src} and text' doesn't work.
$value = '{img:Src} some text {border:Solid} more text {img:Lrg}';
preg_match_all ('/^\{.*\}$/', $value, $foo);
trigger_error(print_r($foo, true));
//Should be an array of 3 items: {img:Src}, {border:Solid}, {img:Lrg}

Open in new window

0
interclubs
Asked:
interclubs
  • 2
1 Solution
 
Ray PaseurCommented:
Try removing the ^ and $ from it.
0
 
Ray PaseurCommented:
This seems to work.
http://www.laprbass.com/RAY_temp_interclubs.php
<?php // RAY_temp_interclubs.php
error_reporting(E_ALL);


// MAKE A REGULAR EXPRESSION
$rgx = '/\{(.*?)\}/';
$value = '{img:Src} some text {border:Solid} more text {img:Lrg}';
preg_match_all ($rgx, $value, $foo);

var_dump($foo);

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now