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
https://forums.phpfreaks.com/topic/92690-embed-urls-search-and-replace/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.