Skip to content

Instantly share code, notes, and snippets.

@davepoon
Created December 5, 2012 23:24
Show Gist options
  • Save davepoon/4220464 to your computer and use it in GitHub Desktop.
Save davepoon/4220464 to your computer and use it in GitHub Desktop.
PHP Regex to get src value
<?php
$input_string = '<script type="text/javascript" src="http://localhost/assets/javascript/system.js" charset="UTF-8"></script>';
$count = preg_match('/src=(["\'])(.*?)\1/', $input_string, $match);
if ($count === FALSE)
echo('not found\n');
else
echo($match[2] . "\n");
$input_string = "<script type='text/javascript' src='http://localhost/index.php?uid=93db46d877df1af2a360fa2b04aabb3c' charset='UTF-8'></script>";
$count = preg_match('/src=(["\'])(.*?)\1/', $input_string, $match);
if ($count === FALSE)
echo('not found\n');
else
echo($match[2] . "\n");
?>
@basilmnm
Copy link

cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment