/    Sign up×
Community /Pin to ProfileBookmark

Please help about function preg_match_all(); – don’t understand why it doesn’t work

Hello!

I have a variable like this:

[code=php]$string =”<FONT color=”#548dd4″>Text</FONT>”;[/code]

To get data [B]#548dd4[/B] I use preg_match_all() below and it works.

[code=php]
<?php
$string =”<FONT color=”#548dd4″>Text</FONT>”;
preg_match_all(“/color=”(.*?)”/si”, $string, $matches);
print $matches[1][0]; //will out put #548dd4
?>
[/code]

BUT if my variable like this (without double quote ” )

[code=php]$string =”<FONT color=#548dd4>Text</FONT>”;[/code]

then how come this code below doesn’t get data #548dd4

[code=php]
<?php
$string =”<FONT color=#548dd4>Text</FONT>”;
preg_match_all(“/color=(.*?)/si”, $string, $matches);
print $matches[1][0]; //out put BLANK – not #548dd4 – WHY ?? and How to make it work
?>
[/code]

Thanks for helping me.

Kevin.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@knowjFeb 27.2007 — i know its not a solution but inline styles SHOULD NOT be used (i understand you may just be using this as an example)

but you should quote all tags

<font> is depreciated

and inline styles is bad

again: i understand you may just be using this as an example but i thought i should bring it up in case your making some horrible markup judgements
×

Success!

Help @kevin31 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...