paulintodarkness Posted February 14, 2009 Share Posted February 14, 2009 Trying to strip out all from javascript tag except for src url, but all regex i've tried, regex buddy etc doesn't seem to return what i am looking for..hit a wall, can anyone help? Basically I need to do this: I submit a form: I send the form information to a page which captures the form textarea content in a variable called $ex_js which I get as a post like this: $ex_js = $_POST["content"]; if the contents in $ex_js contain a javascript tag like this: <script type="text/javascript" src="http://www.abc.com"></script> I want to strip out EVERYTHING except for http://www.abc.com and return in a variable named $result so when i echo $result it's simply just http://www.abc.com Thanks Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted February 14, 2009 Share Posted February 14, 2009 $_POST["content"] = 'some garbage......<script type="text/javascript" src="http://www.abc.com"></script>....more garbage...'; // form content... $ex_js = preg_replace('#<script type=[\'"]text/javascript[\'"].+?src=[\'"]([^\'"]+)[\'"].*?>.*?</script>#i' , '$1', $_POST["content"]); echo $ex_js; Quote Link to comment Share on other sites More sharing options...
paulintodarkness Posted February 15, 2009 Author Share Posted February 15, 2009 Thanks, Sorry a bit of a novice to this. Not sure how to apply this. Here is the code i am using: <? $ex_js = $_POST["content"]; ?> <html> <head> <title>page</title> </head> <body> <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="content"> <textarea cols="85" rows="6" name="content"> </textarea> <input type="submit" value="Validate" /> </form> </body> </html> Where should I apply this code? $_POST["content"] = 'some garbage......<script type="text/javascript" src="http://www.abc.com"></script>....more garbage...'; // form content... $ex_js = preg_replace('#<script type=[\'"]text/javascript[\'"].+?src=[\'"]([^\'"]+)[\'"].*?>.*?</script>#i' , '$1', $_POST["content"]); echo $ex_js; I want to strip the javascript tag when the form posts. tried this: Added this in the form's textarea: some garbage......<script type="text/javascript" src="http://www.abc.com"></script>....more garbage... Submitted the form, had this code to capture the above in the post. $stuff = $_POST["content"]; $ex_js = preg_replace('#<script type=[\'"]text/javascript[\'"].+?src=[\'"]([^\'"]+)[\'"].*?>.*?</script>#i' , '$1', $_POST["content"]); echo $ex_js; Doesn't seem to work. Am i doing something wrong? Thanks for you help Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted February 15, 2009 Share Posted February 15, 2009 I supplied the meat and potatoes, you supply the gravy. When posting on these boards, it is assumed that you have general working knowledge of PHP. Not to be difficult, impolite nor rude, but I would suggest you take a step back and advance yourself in PHP. There are plenty of books / online tutorials and other resources available at your disposal. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.