Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

regex issue

General discussions related to php

Moderators: macek, egami, gesf

regex issue

Postby edwardsmarkf » Tue Jun 10, 2014 5:41 pm

hello all - first time posting to this forum.

i am trying to use preg_match_all, but i am running into trouble. in plain English, i want to parse out everything in the quotes. for some reason, i cant seem to use the closing angle-bracket. i tried just ">" and "\>" but no luck. the first example without the closing angle-bracket works fine, but the subsequent ones only grab the LAST span occurrence and ignores the first one.

(for the regex-challenged, the ?: tells regex to skip indexing the value in the parenthesis)

if somebody could please have a look at this code and see what i am doing wrong i would appreciate it!

Code: Select all
$string = '<span style="font-size:10px;"><span style="color:#aaaaaa;">test font</span></span>';

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)")+/', $string, $matches);
var_dump($matches);

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)">)+/', $string, $matches);
//                   i added this right angle-bracket: >
var_dump($matches);

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)"\>)+/', $string, $matches);
//          i added this back-slash and angle-bracket: \>
var_dump($matches);


thank you all very much.

PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)
edwardsmarkf
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jun 10, 2014 5:27 pm

Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron