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);
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 am trying to get string through input box from user
user can add only numbers in the string the format of a string is like this
Example
123456,111111,122335
123456 111111 122335
only "," or " " are allowed after 6 digits of number like show in example
You can use
^(?:(?:\d{6},)*|(?:\d{6}\s+)*)\d{6}$
Regex Demo
This regexp is for 3 groups of 6 digits:
\d{6}(?: |,)\d{6}(?: |,)\d{6}
You can test it here.
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;
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 have a set of strings that are in the format of This.is.An.Example.YYYY.More.Data.Here where YYYY is any valid year and I would like to get the string up until YYYY in the example so I would end up with a string that is This.is.an.Example.
You can do this with a simple regex, \d{4}.
$splitted = preg_split('~\d{4}~', 'This.is.An.Example.2015.More.Data');
echo $splitted[0];
Output:
This.is.An.Example.
This will split one every 4 continuous single numbers (0-9). Since you only care about what is the first instance use the 0 index.
Sample: http://sandbox.onlinephpfunctions.com/code/640224e9bda3e6cd5c3e012a1bb901dc1e6a34b4
Vague question, so I choose the simplest version ;-)
<?php
$in = 'This.is.An.Example.2015.More.Data.Here';
$out = strstr($in, '.2015', true);
echo $out;
prints This.is.An.Example
see http://docs.php.net/strstr
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'