Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_replace arrays, and deliminators

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
Hi,

I have a template (HTML) containing markers, for example <%MARKED%>. The PHP script has an array of markers, and an array of replacement content.

The script uses preg_replace($markers, $content, $html) and it's not behaving as expected.

The output contains the content as hoped, but it also contains the first and last character of the marker.

For example..

<%MARKED%> will be replaced with <hello world> and I don't want those first and last characters. It's the same no matter which characters are used.

%...% <...> !...! etc all give the same behaviour.

I hope this made sense, it was tricky to explain :-/

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Code:
$markers = array(
"<%MARKED%>",
"<%ANOTHER MARKER%>");
$replacements = array(
"Hello World", 
"Another Hello World");
$newtext = str_replace($markers, $replacements, $originaltext);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top