Preg_Replace with Special Characters not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Preg_Replace with Special Characters not working

Post by tecktalkcm0391 »

I cant get the preg_replace to match [#A] where a can be any letter, uppercase or lowercase to replace with <a name=""></a>
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: Preg_Replace with Special Characters not working

Post by tecktalkcm0391 »

using this now...

Code: Select all

<?php 
$str = "[#A]Bah blah blah ba[#B]";
echo preg_replace("/\[\#[(A-z)]\]/", '<a name="#$0"></a>', $str);
?>
 
but not getting excatly what i want, and how I can figure out how about getting it.... the above returns

<a name="#[#A]"></a> instead of <a name="#A"></a>... how can i fix that?
Post Reply