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);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
hi i want to create string in laravel with foreach and that string must be like this sample:
'item1,item2,item3'
Pay attention to commas and quotation marks.
anyone can help me?
you can use implode function.
Have a look at https://www.php.net/implode
It does exactly that with arrays.
example:
$string = implode(",", $array);
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 tried several times to find a solution without an idea of how to approach it.
I want to convert this string: '^3816[4-6].*$';
Into this: '38164, 38165, 38166';
In other words I want to genarate all the possible options of a given string: 'XXXX[2-7]';
So the output should be: 'XXXX2, XXXX3, XXXX4, XXXX5, XXXX6, XXXX7';
please help me to solve this issue if anyone know how to accomplish it.
Use a RegExp ;)
<?php
$string_pattern = '^3816[4-6].*$';
$pattern = '/^\^(.*)\[(.)-(.)\](.*)\$$/';
preg_match($pattern, $string_pattern, $matches);
for ($i = $matches[2]; $i <=$matches[3] ; $i++) echo $matches[1].$i.$matches[4]."\n";
?>
The question is: what really contains $matches[4]?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to add + sign where ever I find space in string.
I have something like
$str = "How are you.? I'm fine."
should be
$C_str = "How+are+you.?+I'm+fine."
How I can do this in php.?
Any better idea.?
If there is just single space between chars use
$C_str = str_replace(' ','+',$str);
or if there can be more that just space like tab,etc then use this one
$C_str = preg_replace( '/\s+/','+', $str);
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'