Jump to content


Photo

2 preg_replace question


  • Please log in to reply
3 replies to this topic

#1 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 June 2006 - 10:55 PM

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


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 June 2006 - 11:06 AM

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);

#3 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 June 2006 - 01:12 PM

[!--quoteo(post=386337:date=Jun 21 2006, 02:06 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 21 2006, 02:06 PM) View Post[/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..


#4 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 June 2006 - 05:35 PM

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

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


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

thx for ur time..

good coding..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users