Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: strippping text

  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    195
    Thanks
    26
    Thanked 0 Times in 0 Posts

    strippping text

    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?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,497
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Try the test script below ...
    using a nice little function that parses a string between two strings ....

    PHP Code:
    <?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);
    }


    ?>


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •