Jump to content

2 preg_replace question


teomanersan

Recommended Posts

hi guys..

i`d like to ask how to accomplish using urlencode() function inside a preg_replace function and inverse of preg_replace..

$string = preg_replace('#\[star](.*?)\[/star\]#is','<a href="blabla.php?ara=\\1">*</a>',$string);

works fine.. but i have to add a urlencode() to the link... so i tried some stuff like below

$string = preg_replace('#\[star](.*?)\[/star\]#is','<a href="blabla.php?ara='.urlencode(\\1).'" >*</a>',$string);

which is not working.. it`s encoding \\1 and not the $string.. how can i make it encode the string ??

the second question is how can i take the inverse of this preg_replace().. simply when i get
$string = <a href="blabla.php?ara=\\1">*</a>' , i want it to write [star]$string[/star]

thanks for your time..

good coding..
Link to comment
https://forums.phpfreaks.com/topic/12495-2-preg_replace-question/
Share on other sites

[!--quoteo(post=386337:date=Jun 21 2006, 02:06 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 21 2006, 02:06 PM) [snapback]386337[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You'll want to use the e modify like so:
$string = preg_replace('#\[star](.*?)\[/star\]#ise','<a href="blabla.php?ara='.urlencode(\\1).'" >*</a>',$string);
[/quote]


thanks a lot for the reply but this code is not working..

i googled this problem and couldn`t find much and the ones i found didnt work :(

please, i need help about this problem..

thx for ur time

good coding..
ok i figured out it and did something like this and it works..

[code]
$string = preg_replace("#\[star](.*?)\[/star\]#ise", "'<a href=\"/blabla.php?ara='.urlencode('\\1').'\" >*</a>'",$string);
[/code]


i need a reference manual something to sort out this syntax problems, any link / help is highly appericiated..

thx for ur time..

good coding..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.