Remove character from image url [duplicate] - php

This question already has answers here:
How to remove the querystring and get only the URL?
(16 answers)
Closed 8 years ago.
I'm new to PHP and WordPress, and i need to import image from a offshore website with the WordPress function download_URL().
My problem is, i have URL that look like that :
http://www.test/img/FMR.jpg
But i have also URL that look like that :
http://www.test/img/FMR.jpg?Qq_0y12h
And can i have remove everything that is after the .extension if there something?

you can use preg_replace, I did this little example for you.
<?php
$url = "http://www.test/img/FMR.jpg?Qq_0y12h";
echo "url = $url\n\n";
$urlFormatted = preg_replace("/\?.*$/", "", $url);
echo "urlFormatted = $urlFormatted\n";
?>

Related

Get portion of URL with PHP [duplicate]

This question already has answers here:
Get parts of URL in PHP
(4 answers)
Closed 1 year ago.
I had previously been using basename to grab the last part of my URL however have noticed some issues if my URL contains parameters.
So if my URL is this:
https://www.google.com/test-page/?utm_source=test
How would I pull test-page from this?
You split it by the / delimiter, and then take the fourth item
$link = 'https://www.google.com/test-page/?utm_source=test';
$split = explode('/', $link);
if(isset($split[3]))
{
echo $split[3];
}

how to store the url sting parameter in the $variable [duplicate]

This question already has answers here:
Get Last Part of URL PHP
(14 answers)
Closed 2 years ago.
Hi i am working on a wordpress website and i am little stuck into one situation,
https://jobicons.com/newsite/my-profile/
the above is the url of my web site i only want to store the my-profile parameter in the $variable , is there any way how can i do this?
Thanks in advance.
using php it is as simple as doing this:
<?php echo basename($URL);
but since you're using wordpress, this is how you should be able to get the slug name for a post
<?php
global $post;
$post_slug = $post->post_name;
?>

Remove url from string using PHP [duplicate]

This question already has answers here:
Get path from URL
(2 answers)
Closed 8 years ago.
Can anyone please tell me how to remove url from a string using PHP
I have this string
src="http://cdn1.vox-cdn.com/uploads/chorus_image/image/34918177/layering__1_.0_standard_90.0.png"
Desired Output:
src="/uploads/chorus_image/image/34918177/layering__1_.0_standard_90.0.png"
You can use the parse_url() buil-in php function for this.
For example:
<?php
$url = 'http://cdn1.vox-cdn.com/uploads/chorus_image/image/34918177/layering__1_.0_standard_90.0.png';
$parsed_url = parse_url($url);
var_dump($parsed_url);
?>
Output:
So, after the url is parsed, the bit you want is found on $parsed_url['path']. Hope this helps.

How to extract last part in PHP? [duplicate]

This question already has answers here:
How do I extract query parameters from a URL string in PHP?
(3 answers)
Closed 8 years ago.
This would be an example:
redirect
dynamic_word can be changed because it is dynamic. When click "redirect", dynamic_word will be extracted. So, how to extract it in redirect.php file ? Thanks !
Use $_GET to get parameters from an URL
<?php
$thatName = $_GET['q'];
echo $thatName;
Result
dynamic_word
If samitha's correct looking answer is incorrect then perhaps you mean you would like to extract the dynamic word from a string.
In that case you could do
<?php
$string = 'http://mywebsite.com/redirect.php&q=dynamic_word';
$ex_stirng = explode('&q=', $string);
$dynamic_word = $ex_string(1);
?>
Or even use the strstr function:
http://www.php.net/manual/en/function.strstr.php

Remove Unwanted Gap from PHP-Generated URL [duplicate]

This question already has answers here:
Removing a space
(4 answers)
Closed 9 years ago.
This script sends instructions to delete a user from a database when a php-generated link is clicked.
<?php
$user = $_GET['user'];
$zip = $_GET['zip'];
$url = "<p>http://domain.org/remove.php?do=delete";
$url .= "&removeid=".$user."&rcrd=".$zip."</p>";
echo $url;
?>
But the generated link has an unwanted space after "&removeid=" producing the following:
http://domain.org/remove.php?do=delete&removeid= 160294&rcrd=41233
The link is, therefore, unclickable.
Suggestions appreciated.
use the function trim - http://php.net/manual/en/function.trim.php
trim($user);

Categories