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 am trying to convert string to an array format in my code below. I tried to use explode but it returns my results as
In my code i have
File.php
$dial_deustche_no = $payloadArray[1];
dial_deustche_no = 49744990,49010101 //result
$numbers = json_encode([0 => $dial_deustche_no]);
$numbers =. ["49744990,49010101"] //result
When i use explode results looks like
explode(',', $numbers);
//results
array (
0 => '["49744990',
1 => '49010101"]',
)
This is how i want my results to look like
$numbers = ['49744990','49010101']
PS: Beginner in laravel PHP
Explode it before doing the json_encode
$numbers = explode(',', $payloadArray[1]);
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 5 years ago.
Improve this question
I want extract data from string
Example, i have this :
n97(nok)_100(ok)_n41(145)_23(ok)
I want get the 2 string beginning by "n" :
n97(nok) and n41(145)
And after for this 2 string i need get in variable
97 => nok and 41 => 145
can you help me ?
Thanks you
Use regex /n(\d+)\((.+?)\)/ to find patern and array_combine to get result
$str = 'n97(nok)_100(ok)_n41(145)_23(ok)';
if(preg_match_all('/n(\d+)\((.+?)\)/', $str, $m)) {
$res = array_combine($m[1], $m[2]);
}
print_r($res);
demo
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 5 years ago.
Improve this question
I have a array of random generated strings looking like this:
63njpn5u
byrtg1za
ht6wnz39
em1yyrju
2ytoxfxl
n5kaho14
zg92pg4n
gr9e7i01
u3t07ai4
I need a php code that will cycle trough these and output the ones back that contain one number. So in the example above I would've gotten back:
2ytoxfxl
em1yyrju
byrtg1za
I've tried using preg_match_all but I cant figure out how to use this with a array.
What you need is preg_grep:
print_r(preg_grep('/^\D*\d\D*$/', $your_array));
You can count like using string method :
$string = "2ytoxfx3l";
echo $int = strlen(intval(preg_replace('/[^0-9]+/', '', $string), 10));
Group of element:
$string = array( "63njpn5u","byrtg1za","ht6wnz39");
foreach($string as $str){
echo strlen(intval(preg_replace('/[^0-9]+/', '', $str), 10));
}
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 have a long string(in one line), and i want to split it using regex.
the string:
2013-10-28;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
2013-10-29;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
2013-10-30;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
2013-10-31;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
i tried using explode like so:
explode("2013",$string);
but it removes the delimiter.
so how can i split it using regex?
thanks :)
output should look like:
[0]=>2013-10-28;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
[1]=>2013-10-29;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
[2]=>2013-10-30;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
[3]=>2013-10-31;;0;;0;;0.00;;0;;0;;0;;0.0;;0;;0;;0;;0.00;;0.00
You can try this
$lines = array();
$lines = explode("2013",$string);
foreach($lines as $key => $value)
{
$data = array()
$data = explode(";;",$value);
$lines[$key]['data'] = $data
}
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 have written some php code, trying what is to assign a string (tag_of_organization) to a variable and then latter to assign it to array newvar. As i am totally new to php and search a lot for it but cannot find anything, so i am asking it here how to do this. here it is
$organ='tag_of_organization';
$newvar = array();
$newvar["tag_of_organization"] =$organ;
Try with:
$newvar[$organ] = $organ;
You are already correct. put print_r to test print your array
$organ='tag_of_organization';
$newvar = array();
$newvar["tag_of_organization"] =$organ;
print_r($newvar);
Output
Array ( [tag_of_organization] => tag_of_organization )
Update
you want dynamic result
$organ='tag_of_organization';
$newvar = array();
$newvar[$organ] =$organ;
print_r($newvar);
Output
Array ( [tag_of_organization] => tag_of_organization )
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
This is my array in php
$a is my array
Array
(
[0] => class="date-display-single">24-Feb-2013
[2] => 11:35
[3] => AM
)
How do I remove class="date-display-single"> from array[0]?
Several ways... But the simplest one is to do:
$a[0] = str_replace('class="data-display-single">', '', $a[0]);
This simple statement should do exactly that:
$a[0] = substr($a[0], strpos($a[0], '>') + 1);
That said, it all depends on how you ended up with that array in the first place; it seems things can be fixed higher up in the code.
there you are:
$a[0] = str_replace('class="date-display-single">','',$a[0]);
but i would do it in the string, before you explode your date string. no in the array after
Check out unset()
You could try something like:
unset($a[0]);
Try this
str_replace('class="date-display-single">', '', $a[0]);