Help Parsing URL

Discussion in 'PHP' started by minnseoelite, Nov 26, 2007.

  1. #1
    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
     
    minnseoelite, Nov 26, 2007 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should us an .htaccess redirection with a url scheme better than the one you're trying !
     
    selling vcc, Nov 26, 2007 IP
  3. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wow thousands of webmasters and no one knows how to parse a URL?
     
    minnseoelite, Nov 27, 2007 IP
  4. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    <?php 
    $url="http://www.site.com/?q=1&x=2 ";
    $url_array = parse_url($url);
    
    echo '<pre>';
    print_r ($url_array);
    echo '</pre>';
    
    
    PHP:
     
    selling vcc, Nov 27, 2007 IP
  5. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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:
     
    imvain2, Nov 27, 2007 IP
  6. minnseoelite

    minnseoelite Peon

    Messages:
    845
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok thanks peeps i will give that a try
     
    minnseoelite, Nov 30, 2007 IP