473,598 Members | 3,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strip script tags and contents in them?

161 New Member
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 2524
5,821 Recognized Expert Expert
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
161 New Member
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
8,658 Recognized Expert Moderator Expert
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.

Nov 24 '08 #4
938 Recognized Expert Contributor

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.
Nov 24 '08 #5
6,050 Recognized Expert Expert
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
5,821 Recognized Expert Expert
How would you know? ;)
Nov 24 '08 #7
161 New Member
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
5,821 Recognized Expert Expert
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

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 any help!
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 parameter which can be found in the xml file. I've done something like <xsl:variable name="id" select="person_id"/> <a href="http://localhost/CGI/detailsselection.cgi?ID=$id"><xsl:value-of select="name"></xsl:value-of><xsl:value-of...
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 to strip out this css so that I can apply my own style sheet; does anyone know whether there is a way to do this, other than manually? Either a way to export the data from Excel that doesn't include the css formatting, or a utility that will...
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; } function makeArray0() {
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 file and call it with the <script src="filename.js"></script> tags as I do for many other .js files. But, when I try to do that way, it doesn't work right. It will display the banner text, but only on the 0,0 page coordinate and doesn't slide....
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 content="JavaScript"> <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5"> And I am wondering if it is safe to remove them after I compile the ASP.NET application, or if it is possible to have VS.NET 2003 not put
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 exclude this ?
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 find styles embedded within the tags eg: <h3 id="pageName">Have a great day!! </h3> This throws an error, whereas <h3 >Thank you for your purchase! </h3works like a charm. It also falls over when crappy code has <h3>&nbsp;</h3between the tags.
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.
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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 we have to send another system

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.