Forum Moderators: coopster
Unfortunately I'm having some trouble getting the expressions correct.
Say my test phrase is <em>Hello world</em> and I want to turn that into <strong>Hello world</strong>. My first expression was this
preg_replace('/\<em\>([^ ]+)\<\/em\>/', '<strong>$1</strong>', $test);
Naturally, this didn't work. I think my problem is the ([^ ]+) and $1 but I don't know how it's wrong. Any suggestions?
The goal of my code is to be able to replace tags, while leaving the text inside alone. Currently if I have two identical pieces of code that I'm trying to replace, it only does half.
ie. <em>Hello world</em><em>Hello world</em>
should be
<strong>Hello world</strong><strong>Hello world</strong>
but instead it's
<strong>Hello world</em><em>Hello world</strong>
Any suggestions?