Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
regexp replace part of pattern problem
Old 01-04-2011, 01:11 AM regexp replace part of pattern problem
Junior Talker

Posts: 4
Trades: 0
I'm trying to replace a color in css file using preg_replace. First i have tried to replace part of pattern using $1 and $3, but it didn't work. Next i have extracted the pattern into $matches array, replaced one of them and combined them as new replace string. It worked as expected. I think there is difference how parts of pattern defined by () are matched by preg_match->$matches_array and preg_replace->$1,$2,$3...

I know my explanation of the problem is not good at all so i'm attaching very simple php file (zipped) that show the error.

Can someone help me understand what i'm doing wrong?
Attached Files
File Type: zip test.zip (562 Bytes, 2 views)
__________________

Please login or register to view this content. Registration is FREE
Torrodon is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-04-2011, 05:52 AM Re: regexp replace part of pattern problem
Junior Talker

Posts: 4
Trades: 0
I've found this exception in the documentation. (http://php.net/manual/en/function.preg-replace.php)
I've also found my second mistake - the solution does not work with double quotes. So finally this is working:
PHP Code:
$new_str_1 preg_replace($pattern,'${1}'.$newcolor.'$3',$str); 
Too bad this is unlikely to help anyone else due to my poor description.
__________________

Please login or register to view this content. Registration is FREE
Torrodon is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to regexp replace part of pattern problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27226 seconds with 13 queries