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);
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 1 year ago.
Improve this question
http://oktrad.dotdigital.pk/t/Alemán%20(Alemania)-Alemán%20(Austria)
basically i want to remove %20 from url. There no any Query parameter in url. i want remove %20 to underscore '_' or same as space.
http://oktrad.dotdigital.pk/t/Alemán (Alemania)-Alemán (Austria)
http://oktrad.dotdigital.pk/t/Alemán_(Alemania)-Alemán_(Austria)
You can use urldecode() :
urldecode('http://oktrad.dotdigital.pk/t/Alemán%20(Alemania)-Alemán%20(Austria)')
//output - http://oktrad.dotdigital.pk/t/Alemán (Alemania)-Alemán (Austria)
Or, you can use str_replace() for convert space to _ :
str_replace('%20', '_', 'http://oktrad.dotdigital.pk/t/Alemán%20(Alemania)-Alemán%20(Austria)')
//output - http://oktrad.dotdigital.pk/t/Alemán_(Alemania)-Alemán_(Austria)
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 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 6 years ago.
Improve this question
my string is "mom dad" (also saves the same attribute in table db).
After I query and print to the table, I want to separate a newline with a space. The output should be mom+newline+dad, but it prints "mom dad" without a new line.
Use PHP explode() function like this :
<?php
$input = "mom dad";
$inputArray = explode(" ", $input);
//now inputArray is like this ["mom", "dad", ...]
echo $inputArray[0]."<br>".$inputArray[1];
?>
Hope it helps
Thanks
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 9 years ago.
Improve this question
I need a pattern which is able to find a word wrapped in two signal characters.
Basically something like
$string = "bablabla __test__ blablabla"
preg_match("/__\w__/", $string, $result);
print_r($result);
\w is a single word character. It would match __t__ but not multiple characters like __test__. Try \w+
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 need the regular expression to replace using following rule:
Any integer present before . then no take place.
If no integer present before . then that should be replace.
$input = (contain anything characters, symbols, numbers, floats etc)
Example:
$myString = "Example 1.58 Stack.68";
Output should be
Example 1.58 Stack,68
preg_replace('#(?<!\d)\.#',',',$myString)