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]?
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 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 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'
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 8 years ago.
Improve this question
I want to remove all strings that are like this: "REP_HSC_QUALIFIED" using the following expression, but somehow it is not working. Can somebody help in pointing out my mistake (I rarely use regular expressions, so I do not have good understanding of it).
preg_replace('#REP[a-zA-Z0-9_]+#', '-', $data);
you propably want to do
$data = preg_replace('#REP[a-zA-Z0-9_]+#', '-', $data);