Jump to content

[SOLVED] getting a string replace to ignore HTML


coalduststar

Recommended Posts

i was wondering how i'd go about getting a string replace to ignore anything between angle brackets? i have an SQL search that highlights the search string using a <span></span> tag but i need it to ignore any existing HTML otherwise i get all of the link and formatting code displayed.

any ideas? ???
cheers for the replies. I don't think i can use strip_tags or preg_replace function because i want to keep the HTML for formatting purposes but I'm trying to get my string replace to only insert the <span> tags on the text.

I'm not particularly any good at this but like- If there's "<...>" then don't use the str_replace.

i have something similar to this at the minute:
[code]str_replace($SearchString, "<strong>$SearchString</strong>"
,$row_rsSearchResults['title_art'])[/code]

but say the user only inputs "h" in the search box- the results are emboldened so a if there's a link in the database it ends up looking like this:
[code]< a <strong>h</strong>ref="<strong>h</strong>ttp://www.deftones.com">link></a>[/code]

If i use strip_tags it'll pull all the formatting in the results and i think maybe the same with preg_replace - unless i'm thinking of how to use them incorrectly... which is entirely likely.
So if the user searches for "foo" and there is an entry:
My name is foo

It should show up as
My name is <strong>foo</strong>

And if there is an entry
My <a href="foo.com">name</a> is foo

It should show
My <a href="foo.com">name</a> is <strong>foo</strong>

But what you get is
My <a href="<strong>foo</strong>.com">name</a> is <strong>foo</strong>.

Hm. If I understood that right, this seems complicated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.