Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-16-2009, 11:49 PM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
Find and replace, extracting variables
I currently have a script that inserts a video play on my blog, it looks for [video=11] 11 being the video id.
I want to be able to have video variables, such as:
and then have each variable $filename, $width, $height.
This is the code i am using.
function ninexn_the_content( $content )
// find video id
$search = "/\[video=(.*)\]/";
preg_match_all($search, $content, $video_matches);
foreach ($video_matches as $filename)
$search = "[video=".$filename."]";
$replace = ninexnvideo($filename);
$content = str_replace ($search, $replace, $content);
03-17-2009, 12:03 AM #2
- Join Date
- Jun 2007
- Perth, Western Australia
- Thanked 58 Times in 57 Posts
I'm confused on what you want to do but here's something that'll allow the extra variables.
$string = '[video=11&w=600&h=333]';
preg_match_all('#\[video=(\d+)&w=(\d+)&h=(\d+)\]#i', $string, $matches);
if (is_array($matches) === true)
$i = 0;
foreach ($matches as $filename)
$width = $matches[$i];
$height = $matches[$i];
// Do whatever you need
Last edited by Iszak; 03-17-2009 at 12:07 AM.