473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

preg_replace() that will not replace text inside HTML tags

I have big problem, I'm using preg_replace() function for my highlighter function, after searching for particular keyword, once the hightler check box is checked it will highlight the content that matches the search keyword, the problem is, it also highlight the text inside the HTML tags that matches the keywords.

here's the screenshot:



I need a preg_replace() function that will not replace the text inside HTML tags, particularly <img /> tag

you help will be appreciated, thanks!
Mar 27 '07 #1
1 2660
code green
1,726 Expert 1GB
If the user types a search term into the search box and you extract that from the $_POST array into a variable there should be no HTML tags. Also as all user entry is safer if you clean it first you should not be having this problem
Expand|Select|Wrap|Line Numbers
  1. cleanEntry = striptags(trim($_POST['seachterm'])) 
Mar 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Juha Suni | last post by:
Hi! I have managed to live without using too much regular expressions so far, and now that I need one, I need some help too. I have a string containing a (possibly large) block of html. I need...
4
by: Sam | last post by:
Hi Can anyone help me with this problem please? I have a long string that I would like to split into paragraphed sentences. I would like to replace every full-stop or period ('.') with the...
3
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
3
by: JaNE | last post by:
I need to replace all possible html tags in user input but don't want to replace bold and italic start and end tags, so I made folowing line, but it replaces only "one-letter-tags" like paragraf or...
9
by: ihatzi | last post by:
Hey all! I am having a bit of trouble getting this to work. You all are probably familiar with the code that strips HTML tags: $PageText = preg_replace("/<.+?>/","",$WebPage); What I need...
3
by: amygdala | last post by:
Hi there, I'm trying to replace single quoted attributes in HTML tags with double quotes. What I've come up with is this: function replaceSingleQuotesInsideTags( $input ) { $output =...
3
by: Silvertype | last post by:
Hi guys, I have these html tags: <input type="text" id="txtName" name="txtName" /> <textarea id="taHello" name="taHello">hello world</textarea> which I want to replace with the following...
1
by: Sbudah | last post by:
Hi All, I have relatively moderate experience with PHP but preg_replace is not one of my strong points. I need HELP with the following: I have 5 <div> tags whose values are sent to a PHP page...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.