TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-01-2010, 08:09 PM   #1 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default preg_replace within preg_replace

Helly all,

I'll try to explain my question as short as possible.
I have [ url=javascript:document.location='http://www.google.com']test[/ url]

and I simply replace the [url part with the normal <a part, but you can see the javascript part in it. For this I would like to use a second replace.
So the first regex will be like '/[url=(.*?)]/' and change it to <a href='$1' etc., but I want to check the $1 for javascript. So my first thought was something like <a href='strip("$1"), but that won't work since php acts like $1 is a normal string ....

I have read some about the e modifier and preg_replace_callback, but i'm not finding the solution yet.

Could someone help me and show me an example of how to do this ?
Parvus is offline  
Reply With Quote
Old 02-02-2010, 03:10 PM   #2 (permalink)
The Wanderer
Newcomer 
 
Parvus's Avatar
 
Join Date: Aug 2008
Posts: 21
Thanks: 1
Parvus is on a distinguished road
Default

And then an idea came .... I could just do a search for '/[url=(.*?)(javascript?)(.*?)]/' and replace it with '<a href=$1.$3' or something like that.
=')
Parvus is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design