Take out a section of code.

Discussion in 'PHP' started by check, Nov 15, 2006.

  1. #1
    Hi i want to take out a section of this code

    <div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7" type="application/x-shockwave-flash" width="425" height="334" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/xng1d_basketball">-Basketball</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/chentemama">chentemama</a></i></div>
    Code (markup):
    I want to take out this part:

    http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7
    Code (markup):
    and on both ends wrap it with a tag so it looks like:

    <wrap>http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7</wrap>
    Code (markup):
    Thanks, im new to php and cant figure it out for the life of me.
     
    check, Nov 15, 2006 IP
  2. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this should work:
    
    $string = 'your initial string';
    $term = 'http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7';
    $term2 = '<wrap>http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7</wrap>';
    $string = str_replace($term, $term2, $string);
    
    Code (markup):
    This will return the modified initial content with <wrap>http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7</wrap> . Or do you need the link only ?
     
    maiahost, Nov 15, 2006 IP
  3. check

    check Guest

    Messages:
    356
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the contents of the embed code is always changing so this last part 2os6Y9gOZik6r4Az7 is always different. I want the php to somehow find it and wrap it. Does that makes sense?
     
    check, Nov 16, 2006 IP
  4. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry I read it wrong, I have a bit of work to do but I'll be back later and post some code. Yes it can be done.
     
    maiahost, Nov 16, 2006 IP
  5. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #5
    OK here goes :
    in order to get the content every time you'll need to use a regular expression. I am not the best when it comes to it but :

    
    <?php
    $term = '<div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/2os6Y9gOZik6r4Az7" type="application/x-shockwave-flash" width="425" height="334" allowfullscreen="true"></embed></object><br /><b><a href="http://www.dailymotion.com/video/xng1d_basketball">-Basketball</a></b><br /><i>Uploaded by <a href="http://www.dailymotion.com/chentemama">chentemama</a></i></div>';
    
    preg_match('/value=\"(.*?)"/',$term, $matches);
    $match=$matches[1];
    echo $match;
    
    ?>
    
    Code (markup):
    Should do the trick :) Now you have the url value to wrap every time
     
    maiahost, Nov 16, 2006 IP
    check likes this.
  6. check

    check Guest

    Messages:
    356
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks so much rep added. :D :D :D :D
     
    check, Nov 16, 2006 IP