Jump to content

Recommended Posts

More info:

 

the URL will always be in this format. The strings will always be the same in length.

 

Basically we are tracking a self-storage facility unit rentals by location. That's why I need "loc" and "complete." The "thank you" page has "complete" in the URL string. The other values just determine the unit type and transaction ID.

Link to comment
https://forums.phpfreaks.com/topic/254899-parse-a-url/#findComment-1307007
Share on other sites

Fantastic. I love Pikachu's simple yet efficient idea.

 

Once you've used parse_url, you'll need code to extract what you want from the array.

As an alternate solution, in case you'd like to do it with regex, try this code. If I've understood your request, it should do what you want.

 

Input:

/reserve-unit/?unit=1000123801&loc=1000000174&transaction=1002731154&complete=1000706731

 

Code:

<?php
$pattern=',/([^/]+)/.*?(loc=[^&]+)&[^&]+&([\w]+)=,';
$subject='/reserve-unit/?unit=1000123801&loc=1000000174&transaction=1002731154&complete=1000706731';
preg_match($pattern,$subject,$match);
for($i=1;$i<count($match);$i++) // or in this case, 4 instead of count($match)
echo $match[$i].'<br />';
?>

 

Output:

reserve-unit

loc=1000000174

complete

 

Please let me know if you'd like further details. :)

Link to comment
https://forums.phpfreaks.com/topic/254899-parse-a-url/#findComment-1307035
Share on other sites

Fantastic. I love Pikachu's simple yet efficient idea.

 

Once you've used parse_url, you'll need code to extract what you want from the array.

As an alternate solution, in case you'd like to do it with regex, try this code. If I've understood your request, it should do what you want.

 

Input:

/reserve-unit/?unit=1000123801&loc=1000000174&transaction=1002731154&complete=1000706731

 

Code:

<?php
$pattern=',/([^/]+)/.*?(loc=[^&]+)&[^&]+&([\w]+)=,';
$subject='/reserve-unit/?unit=1000123801&loc=1000000174&transaction=1002731154&complete=1000706731';
preg_match($pattern,$subject,$match);
for($i=1;$i<count($match);$i++) // or in this case, 4 instead of count($match)
echo $match[$i].'<br />';
?>

 

Output:

reserve-unit

loc=1000000174

complete

 

Please let me know if you'd like further details. :)

 

I think this is exactly what he was looking for.  Thank you very much.  I will post once it has been confirmed.

Link to comment
https://forums.phpfreaks.com/topic/254899-parse-a-url/#findComment-1307039
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.