473,417 Members | 1,483 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,417 software developers and data experts.

preg_replace(not all tags)

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 underline tag, it
doesn't replace body, div, span tags...
Can anyone help me with this?

$txt = preg_replace('/<\/?[^bi]>/i', ' ', $txt);

and problem more: I would like to keep <br> tag and would like to change
<p> to <br> (and discard </p>)... and... that's it.

maybe:
(just as idea, those |?\/... are very confusing to me. I'm still novice
in php)

no_html ($txt) {
$input = array ("'<p>tag'",
"'<br>,<b>,<i>,</b>,</i>tags"
"'<any_other>tag'");

$output = array ("'<br>'"
"'<br>,<b>,<i>,</b>,</i>tags'");
"' '");

$txt = preg_replace ($input, $output, $txt);
}

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #1
3 3153

strip_tags($input,"<i><b>");
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #2
porneL wrote:

strip_tags($input,"<i><b>");

Be careful with this though. Allowing <b> also means allowing this:
<b STYLE="font: 72pt Times New Roman">TEXT HERE</b>

(Example by Paul Hudson in his excellent work: Practical PHP Programming
at www.hudzila.org)

You may want to customize or create a wrapper around strip_tags when
used with exceptions.

Schraalhans
Jul 17 '05 #3
"pornel" wrote:
strip_tags($input,"<i><b>");
--
* html {redirect-to: url(http://browsehappy.pl);}


Besides that, when I want to deal with exceptions like this, I usually
change the exceptions (using str_replace) to something else that regex
won’t catch, run the regex, and change them back. This may be
inefficient at times (depending) but surely it is a lot less taxing on
my brain cells.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-preg_rep...ict188375.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=639933
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
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'...
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...
1
by: otrWalter | last post by:
I have a very specific need. Too long to get into what and why here (If you please). I have this test code... $_str = "testing that'S supposed to work!"; // Notice the CAP 'S, this is the...
1
by: countocram | last post by:
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...
2
by: Peter Parker | last post by:
What is the best way to delete tags n times from either the beginning or the end of a String? For example, to delete "someString1" and "someString2" along with surrounding <someTag>'s with n=2 and...
4
by: shehabic | last post by:
Hello I'm Using The Following Code To Do 2 things 1-Convert Tags To Lower Case 2-Add Quotes To Attributes That Doesn't Have Quote but i'm having problems with some attributes. The Functions...
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: RuthC | last post by:
Hi, I am using this code to make my query nice // Make nice query, remove multiple: spaces, '`' (safe slashes), 'AND', 'OR', ... $pattern = array ( '/(AND)+/', '/(OR)+/', '/\s+/', '/`+/',...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.