...

View Full Version : strippping text



ketanco
05-20-2011, 04:40 AM
Hi, I would like to strip a youtube embed text, so that I can enter it into my blog, as a video. I want to strip the bold section out of the whole thing;


<object width="640" height="390"><param name="movie" value="http://www.youtube.com/v/KLepY1AsaRk&hl=en_US&feature=player_embedded&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/KLepY1AsaRk&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></embed></object>


so that it becomes this:

http://www.youtube.com/v/KLepY1AsaRk&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash

call the first long link as $original for instance. (as I will be entering the first text into a form, to strip it)

how can i do that?

mlseim
05-20-2011, 06:03 PM
Try the test script below ...
using a nice little function that parses a string between two strings ....



<?php

$string='<object width="640" height="390"><param name="movie" value="http://www.youtube.com/v/KLepY1AsaRk&hl=en_US&feature=player_embedded&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/KLepY1AsaRk&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></embed></object>]';

$parsed = get_string_between($string, "src=\""," allowfull");

echo $parsed;


function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}


?>





.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum