coalduststar Posted January 22, 2007 Share Posted January 22, 2007 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? ??? Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/ Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 take a look at [url=http://www.php.net/preg_replace]preg_replace[/url] Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166335 Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 php.net/strip_tags Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166336 Share on other sites More sharing options...
coalduststar Posted January 22, 2007 Author Share Posted January 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166374 Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 So if the user searches for "foo" and there is an entry:My name is fooIt should show up asMy name is <strong>foo</strong>And if there is an entryMy <a href="foo.com">name</a> is fooIt should show My <a href="foo.com">name</a> is <strong>foo</strong>But what you get isMy <a href="<strong>foo</strong>.com">name</a> is <strong>foo</strong>.Hm. If I understood that right, this seems complicated. Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166381 Share on other sites More sharing options...
effigy Posted January 22, 2007 Share Posted January 22, 2007 See [url=http://www.phpfreaks.com/forums/index.php/topic,122857.msg507830.html]this[/url] topic. Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166384 Share on other sites More sharing options...
coalduststar Posted January 22, 2007 Author Share Posted January 22, 2007 Instant migraine! :D I'm gonna try and digest this- thanks for the pointer. Not sure what the array's for... Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166414 Share on other sites More sharing options...
coalduststar Posted January 22, 2007 Author Share Posted January 22, 2007 Got it! thanks a whole lot! Quote Link to comment https://forums.phpfreaks.com/topic/35226-solved-getting-a-string-replace-to-ignore-html/#findComment-166455 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.