Can I get the value from URL without requesting it ? [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I parse URL GET data having the URL stored in a variable?
Can I get the value from URL without requesting the page ( refresh ) or pressing on a link
I need the value of p from this url
http://palestinianz.com/?page=person&p=Betty-Shamieh-
to use it in the og:title meta tag of Facebook

$url = parse_url("http://palestinianz.com/?page=person&p=Betty-Shamieh-");
parse_str($url['query'], $data);
$p = $data['p'];

Related

How to extract specific value between slashes in a URL? [duplicate]

This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 4 years ago.
I'm working on *.xml file containing pictures.
<pictures>https://images.example.co.uk/products/1835/1835776/large2/29203852.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203856.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203863.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203880.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203859.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203853.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203858.jpg|https://images.example.co.uk/products/1835/1835776/large2/29074560.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203854.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203860.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203876.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203862.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203877.jpg|https://images.example.co.uk/products/1835/1835776/large2/29074561.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203871.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203873.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203865.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203874.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203866.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203872.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203868.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203867.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203870.jpg|https://images.example.co.uk/products/1835/1835776/large2/29074558.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203879.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203864.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203878.jpg|https://images.example.co.uk/products/1835/1835776/large2/29203881.jpg</pictures>
I need to extract product ID from the first image URL https://images.example.co.uk/products/1835/1835776/large2/29203852.jpg which for this example is 1835776.
Question:
What is the correct regular expression to achieve this, considering that some elements within the image URL seperated with / are different for each product (XXXXX)?
https://images.example.co.uk/products/XXXXX/[I-WANT-THIS-ELEMENT]/large2/XXXXXXXX.jpg
Presuming the URL will always be in the same format:
$url = "https://images.example.co.uk/products/XXXXX/[I-WANT-THIS-ELEMENT]/large2/XXXXXXXX.jpg";
$url = explode('/',$url);
$id = $url[5];
echo $id;

How to obtain part of the url with php [duplicate]

This question already has answers here:
How can I get parameters from a URL string?
(12 answers)
Closed 6 years ago.
I am coming up with a way to display user profiles. Right now I am able to insert the user_id into the url when going to a user's profile, but I am unsure of how to get the user_id from the url.
So at the end of the url I have this:
profile?user=41
I just want to be able to get the 41 (please note this number will change per profile) and then set it to a variable.
How would I do this?
<?php
echo $_GET['user'];
?>
all the parameters of the url are stored in the $_GET variable...
The parameter that are in your URL can be retrieved with the
predefined variable:
<?php
//$userId = $_GET["pramName"];
$userId = $_GET["user"];
// or
// using the $_REQUEST variable
?>

How I redirect dynamic url with query string in php? [duplicate]

This question already has answers here:
How do I make a redirect in PHP?
(34 answers)
Closed 6 years ago.
I need to redirect dynamic URL like this "https://test.com?user=abc#gmail.com" to "https://test.com"
If I understand correctly, this URL is coming dynamically with a query string. And you want to remove the query string portion and redirect to this modified URL.
Let's assume the dynamic URL is stored in a variable $url.
Try this:
$url = "https://test.com?user=abc#gmail.com";
$modified_url = strstr($url, "?", true); // Remove the query string, which results in https://test.com
header("location:".$modified_url); // Redirect to the modified URL.
You can store the dynamic part in a variable and use the header() function to redirect your user.
$dynamicPart = "someguy#somedomain.com";
header("Location: https://test.com/index.php?username=".$dynamicPart);
exit;

How can I get URL (with some parameters)? [duplicate]

This question already has answers here:
Get URL query string parameters
(11 answers)
Closed 6 years ago.
I have a form on page, with url like this:
site.com/form.index.html?ref=https://login....
And I get page URL via this code:
http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]
But as result I get not full URL, just this:
site.com/form.index.html
How can I get full URL?
You want to add the query string:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]";
Additionally, you may replace the http bit with $_SERVER[REQUEST_SCHEME]:
"$_SERVER[REQUEST_SCHEME]://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]$_SERVER[QUERY_STRING]"

What to parameter value from returning url in php [duplicate]

This question already has answers here:
GET URL parameter in PHP
(7 answers)
Closed 7 years ago.
I have a client url[www.mysite.com/page.aspx]
when we put this url in browser then it revert the automatically
with this url
[www.mysite.com/page.aspx?|&CC=121&DD=123&AA=323|&CC=321&DD=555&AA=000]
Now we want to fetch that parameter value in php page through php or jquery.
Kindly Help and give the best suggestions.
You can simply use GET
$cc = $_GET['CC'];
$dd = $_GET['DD'];
You can access those values using $_REQUEST or $_GET

Categories