Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have my seo url such as
http://domain.com/product/export-grade-large-size-3-tier-organizer-shelf-and-non-woven-storage-box-with-cover-21665223
at the tail of string there is a number represented an id, which I need it for DB processing, how can I separate and get the last id? I cannot use explode because it may have long string parameter with 'dash'.
thanks.
You can do this with:
$url = 'http://domain.com/product/export-your-url-with-21665223';
$id = substr($url, strrpos($url, '-') + 1);
echo $id;
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a $string = "domain.com/path?query=test";
I need to get of it 2 variables: "domain.com" and "path?query=test"
And then i need transform this variables to looks like this "domain.com/api/path-2?query=test-2"
How must this code looks likes? And it means i need to use function?
Thanks you!
This should work for what you are trying to achieve
$string = "domain.ou/path?query=test";
$str_arr_domain = explode ("/", $string);
$str_arr_params = explode ("?", $string);
$newpath = "/api/path2/";
$final_url = $str_arr_domain[0].$newpath.$str_arr_params[1];
print_r($final_url);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a page with the following url-type:
https://domain.name/brandname
I need it to be 303-redirected to
https://domain.name/constant-category-name/brand_brandname
where the part of a url
constant-category-name/brand_
should be inserted in the url right after the https://domain.name/
filetype= .twig , Opencart 3
Something like this :
<?php
$url = "https://domain.name/brandname";
preg_match('/\/(?:.(?!\/))+$/', $url,$matches);
$brandname = ltrim ($matches[0], "/");
$newurl = "https://domain.name/constant-category-name/brand_".$brandname;
header('Location: '.$newurl);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Hey how can I split string into 2 string, exemple:
$ipadd = "192.168.1.60";
From here I want to print 2 result,
one is: 192.168.1
secend is:60
Always split by the last point and print 2 string.
Everything after the last period:
echo substr(strrchr($ipadd, '.'), 1);
To get everything before it, you first need the position:
$pos = strrpos($ipadd, '.');
echo substr($ipadd, 0, $pos);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I got a base64 encoding string. Now i need to get string is a image type or not.
How it possible when image is in base64 string. I am very confused..
You can do this using
$imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA.';
$Imgpos = strpos($imgData, ';');
$type = explode(':', substr($imgData, 0, $Imgpos))[1];
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Please any one help me. As I am a noobe in PHP coding. Is there any built in function to trim letters in PHP??
Lookup substr()
http://us2.php.net/substr
Should do the trick
$var = 'teststring1234567890';
substr($var, 0, -10);
returns 'teststring'