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

Strip script tags and contents in them?

Ajm113
161 100+
I want too know how I can parse for <script and </script> and replace them with nothing. For some reason my preg_replace isn't working the way I planned it..

I don't have the code of the function since I deleted it and didn't back it up.

So can someone help me out?

Thanks, Ajm113.
Nov 24 '08 #1
8 2514
pbmods
5,821 Expert 4TB
Heya, AJM.

My suggestion, rather than to allow all tags except <script> is to disallow all tags except for certain ones that you have decided are benign.

PHP: strip_tags - Manual
Nov 24 '08 #2
Ajm113
161 100+
I think you mist read my topic, I already have that going, Its just it's not removing the code between the tags. str_replace is the function I want too work with.
Nov 24 '08 #3
Dormilich
8,658 Expert Mod 8TB
it could be that because of the added escape characters your RegEx doesn't work. you can check that by dumping the string to evaluate just before the RegEx.

regards
Nov 24 '08 #4
nathj
938 Expert 512MB
@Ajm113
AJM,

In that case I think you need to tackle the problem in 2 steps:

1. Using str_pos() and substr() you can define a variable that is basically the contents of the '<script>... ...</script>' tags.
2. Using that new variable and the str_replace() function you can replace the new string with ''

Hope that helps.
nathj
Nov 24 '08 #5
Markus
6,050 Expert 4TB
@Ajm113
Unfortunately, Pb is not psychic, although he sometimes likes to believe it; without seeing the current code you are using, how can we point out why it isn't doing as you'd like?
Nov 24 '08 #6
pbmods
5,821 Expert 4TB
@Markus
How would you know? ;)
Nov 24 '08 #7
Ajm113
161 100+
Sorry, substr, isn't going to work in this case, I actually forgot that my code returns line by line in a loop and prints it.

So what would be a good way on telling it not too show text until it see's the </script> tag?

Sorry, wasn't thinking, lol. I am making a mobile viewer and I am trying too cut off CSS and Javascript code.
Nov 25 '08 #8
pbmods
5,821 Expert 4TB
Ah, Ok. Now I see what you're saying.

The first idea that comes to mind would be to do a regular expression along the lines of

Expand|Select|Wrap|Line Numbers
  1. !<script.*?>.+?</script>!
But it sounds like the regexp route wasn't working for you....
Nov 25 '08 #9

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

Similar topics

8
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
by: lievemario | last post by:
I have made a perl script witch gets information out of a database, transfers it into an xml-file file and than I parse this to a html document using xsl. The problem is dat the html doc needs a...
9
by: Julie Miles | last post by:
I need to pull several tables of data from Excel into a web page, but when I use Excel's "Save as web page" function, I get an enormous file containing a massive amount of css formatting. I'd like...
38
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
2
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...
3
by: Danny | last post by:
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...
4
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
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
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?
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
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
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.