473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strip Tags problem

Hallo, all

I have used this function.
$string = strip_tags($p1,'<i><b><u><br><p><font>');

The problem is that the title will be printed as well, but i dont allow the
title tag.

How to i exclude this ?

Thanks

Danny
Jan 9 '06 #1
3 2744
Danny wrote:
I have used this function.
$string = strip_tags($p1,'<i><b><u><br><p><font>');

The problem is that the title will be printed as well, but i dont allow the
title tag.

How to i exclude this ?


remove the title and its contents before applying strip_tags.

<?php
$p1 = '<html><head><title>title</title></head><body><p><a>link with<b>embedded bold</b></a></p></body></html>';

if ((substr_count($p1, '<title>') < 2) && (substr_count($p1, '</title>') < 2)) {
$t1 = strpos($p1, '<title>');
$t2 = strpos($p1, '</title>');
if ($t2 > $t1) {
if ((substr_count($p1, '<head>') < 2) && (substr_count($p1, '</head>') < 2)) {
$h1 = strpos($p1, '<head>');
$h2 = strpos($p1, '</head>');
if (($h2 > $h1) && ($t1 > $h1) && ($t2 < $h2)) {
$p1 = substr($p1, 0, $t1) . substr($p1, $t2+strlen('</title>'));
}
}
}
}

$string = strip_tags($p1,'<i><b><u><br><p><font>');
?>
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 9 '06 #2

Hello,
Yes i know i can do that, but the problem is, that the customer cant. The
customer works from a word file and saves it as an html file. Word always
puts the title in it. Why the strip tag allows title standard?

Danny

Danny wrote:
I have used this function.
$string = strip_tags($p1,'<i><b><u><br><p><font>');

The problem is that the title will be printed as well, but i dont allow
the
title tag.

How to i exclude this ?


remove the title and its contents before applying strip_tags.

<?php
$p1 = '<html><head><title>title</title></head><body><p><a>link
with<b>embedded bold</b></a></p></body></html>';

if ((substr_count($p1, '<title>') < 2) && (substr_count($p1, '</title>') <
2)) {
$t1 = strpos($p1, '<title>');
$t2 = strpos($p1, '</title>');
if ($t2 > $t1) {
if ((substr_count($p1, '<head>') < 2) && (substr_count($p1, '</head>')
< 2)) {
$h1 = strpos($p1, '<head>');
$h2 = strpos($p1, '</head>');
if (($h2 > $h1) && ($t1 > $h1) && ($t2 < $h2)) {
$p1 = substr($p1, 0, $t1) . substr($p1, $t2+strlen('</title>'));
}
}
}
}

$string = strip_tags($p1,'<i><b><u><br><p><font>');
?>
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

Jan 10 '06 #3
Danny top-posted (reformatted) and failed to attribute (corrected):
Pedro Graca wrote:
Danny wrote:
I have used this function.
$string = strip_tags($p1,'<i><b><u><br><p><font>');

The problem is that the title will be printed as well, but i dont allow
the title tag.

How to i exclude this ?


remove the title and its contents before applying strip_tags.

Yes i know i can do that, but the problem is, that the customer cant. The
customer works from a word file and saves it as an html file. Word always
puts the title in it. Why the strip tag allows title standard?


strip_tags removes the <title> tag, just like it removes the <b> or <a>
tags. What it doesn't do is remove the text between the tags.

<?php
echo strip_tags('outer <title>inner <a href="x">link</a> content</title> content');
?>

will output "outer inner link content content"
______^^^^________

Maybe you can try to replace <title> with "<!-- " and </title> with " -->"
if you don't want to check everything like I did on my last post.

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 10 '06 #4

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

Similar topics

8
9333
by: Fazer | last post by:
Hello, I was wondering what would be the easiest way to strip away HTML tags from a string? Or how would I remove everything between < and > also the < , > as well using regex? Thanks for...
2
6617
by: AdamD | last post by:
Does anyone have an example of how to strip HTML tags from an laready existing text file Thanks
1
1900
by: John Grandy | last post by:
Let's say I'm writing an app where various 3rd parties provide content. In code, I store their content in strings. The content typically is plain text , but some providers add-in snippets of...
2
5606
by: localhost | last post by:
I have these in all of my pages: <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name=vs_defaultClientScript...
2
2106
by: Daniel M. Hendricks | last post by:
I'm looking for a function/regex in C# to strip unwanted HTML tags from comments posted to my web site. Previously, it was written in PHP and I used this function to strip unwanted tags: ...
2
2617
by: tshad | last post by:
Is there an easy way to strip HTML tags from Text to get just the plain text? I am using a program called FreeTextBox that lets you format Text in a TextBox. It does this by adding HTML tags...
4
1489
by: Nathan Sokalski | last post by:
I have two asp:ImageMaps in a table cell as follows: <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr valign="top"> <td align="center"> <asp:ImageMap ID="mapBanner"...
4
3016
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
6
1746
by: george | last post by:
hello, which is the best way to strip jscript/vbscript from user input? Is there any module I could reuse? thanks in advance george P.S. the solution must allow users to enter html code.
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7154
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,...
1
6858
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
7360
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...
1
4881
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
4578
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...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.