I'm still a total noob at PHP and am looking for someone to help me parse a URL using PHP The URL that I am trying to parse is this http://www.hotmonkee.com/images/code.php?place=http://s117.photobucket.com/albums/o75/tinapics_album/images/Tagalog/images/whats_up.gif PHP: What I want is when the user clicks on the the a link they are taken to a URL that looks like this http://www.hotmonkee.com/images/code.php?place=Tagalog/images/whats_up.gif PHP: Here is the original version of my code that has the link that takes the user to the above page foreach($arr as $val) { $file = ($pb2folder . 'images/' . $val); $pieces = explode('/',$url2folder); $firstPart = ""; for ($a = 4; $a<(sizeof($pieces)-1);$a++) { $firstPart .= '/'.$pieces[$a]; } echo '<div class="showImages">' . "\n" . '<img src="' . $url2folder . 'images/' . $val .'" alt="' . $val . '" />' . "\n" . '<div align="center">' . "\n" . '<br /><div class="js-kit-rating" starColor="Golden" userColor="Golden" view="combo" path="' . $url2folder . 'images/' . $val .'"></div>' . "\n" . '</div>' . "\n" . '<BR><a href="'.$urlBase.'/'.$pieces[3].'/code.php?place='.$file.'">Get The Code</a>' . "\n" . '</div>' . "\n\n"; PHP: thanks in advance
<?php $url="http://www.site.com/?q=1&x=2 "; $url_array = parse_url($url); echo '<pre>'; print_r ($url_array); echo '</pre>'; PHP:
There are many ways to accomplish what you are asking, here is one. The variable $imgurl will be the /Tagalog/images/whats_up.gif. $url = "http://www.hotmonkee.com/images/code.php?place=http://s117.photobucket.com/albums/o75/tinapics_album/images/Tagalog/images/whats_up.gif"; $findstr = preg_match("/tinapics_album\/images([^(\&|$)]*)/", $url,$matches); $imgurl = $matches[1]; PHP: