Disturbed One Posted April 6, 2011 Share Posted April 6, 2011 Hello, I am a long-time PHP coder, but can never figure out Regex! I am trying to display text that has various tags in it, such as Hello {tag_name_here} etc. How can I replace all instances of these tags so the output would be Hello <span class="blah">{tag_name_here}</span>? Note the { and } need to stay intact surrounding the tag. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/232910-look-for-strings-and-add-html/ Share on other sites More sharing options...
JAY6390 Posted April 6, 2011 Share Posted April 6, 2011 $result = preg_replace('/(\{[a-z0-9_]+\})/i', '<span class="blah">$1</span>', $subject); Quote Link to comment https://forums.phpfreaks.com/topic/232910-look-for-strings-and-add-html/#findComment-1197953 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.