Jump to content

embed urls search and replace.


noexcal

Recommended Posts

Alright on my site people can post "widgets" I want to search these inputs for certain urls.

 

Right now it takes all embed codes and does this

 

<embed src="blah.swf">

turns to

<embed enableJSURL="false" enableHREF="false" saveEmbedTags="true" allowScriptAccess="never" allownetworking="internal" src="blah.swf">

 

What I want to do, is have a white list.

the white list will look something like

 

'youtube.com'

'myflashfetish.com'

 

and I want the regex to check the src="blah.swf'

 

so if the regex saw

 

<embed src="youtube.com?v=3242"> or <embed src="myflashfetish.com/somethingstupid.swf">

it would ignore it.

but if it saw anything else it would do the replacing.

Link to comment
Share on other sites

You could write the regex with a PHP variable called $whitelist, that is stored in your database. Basically, taking entries in the database, processing the mysql output into an array, then impoding the array into $whitelist with the | as the delimiter.

DB:

id - site

1 - youtube

2 - break

 

$whitelist_array = array();
$query = "SELECT site FROM whitelist";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)):
  $whitelist[] = $row['site'];
endwhile;

$whitelist = implode('|',$whitelist_array);

if (eregi("($whitelist)", $user_input_trimmed)){
  // allow it
}

And yes, in the above example, I could have used mysql_fetch_result to be more efficient, just made a choice.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.