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
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 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]);
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 this string
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU
Now the part BYDAY=MO,SU can be in any position like
RRULE:FREQ=WEEKLY;BYDAY=WE,TH;INTERVAL=2;COUNT=5; -> BYDAY=WE
I just want to replace the value of BYDAY=value
let's say I have updated value of BYDAY=FR
I've tried to use str_replace() but the given value of of BYDAY can be anything like MO,TU,WE,TH
Using preg_replace, we can try:
$input = "RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU";
$output = preg_replace("/\bBYDAY=[^;]+/", "BYDAY=FR", $input);
echo $input . "\n" . $output;
This prints:
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=FR
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 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
In PHP, i have strings , similar:
"www.mysite.com/fa/doc/report/67571/مطذح کردنو تت";
"www.mysite.com/fa/571/نهتال اهخع";
"www.mysite.com/fa/";
I want if there are Persian's Chars of string, delete them.
Output:
www.mysite.com/fa/doc/report/67571/
www.mysite.com/fa/571/
www.mysite.com/fa/
How can i do this?
You should try this code.
<?php
echo remove_persian("www.mysite.com/fa/doc/report/67571/مطذح کردنو تت");
function remove_persian($text)
{
return preg_replace('#[^a-zA-Z0-9./]#', '', $text);
}
This will output like this:
www.mysite.com/fa/doc/report/67571/
You can use a regex :
$clean = preg_replace('[^a-zA-Z\/\d\s:]', '', $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 8 years ago.
Improve this question
<h3 class="r">curl - Google search results with php - Stack Overflow</h3>
data-href value regex pattern please.
Can try using this pattern
$str = '<h3 class="r">curl - Google search results with php - Stack Overflow</h3>';
$re = '/data-href=["\']?([^"\' ]*)["\' ]/is';
preg_match($re, $str, $m);
$attr_value = trim(str_replace('data-href=', '', $m[0]), '"');
echo $attr_value;
Output:
http://stackoverflow.com/questions/18682352/google-search-results-with-php