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.
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 ?
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?
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.
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