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? ???
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.