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 months ago.
Improve this question
In the following string there are some numbers followed by two letters "ST". How can I extract all of those numbers?
$str = '104 ST Lorem 104 ipsum (dolor) sit ST, 2000 ST adipiscing 2 2 ST elit.'
In the above string there is 104 ST, 2000 ST and 2 ST.
We can use preg_match_all here with the pattern (\d+) ST\b:
$str = "104 ST Lorem 104 ipsum (dolor) sit ST, 2000 ST adipiscing 2 2 ST elit.";
preg_match_all("/(\d+) ST\b/", $str, $matches);
print_r($matches[1]);
This prints:
Array
(
[0] => 104
[1] => 2000
[2] => 2
)
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 4 years ago.
Improve this question
I have a table with locations stored in the format:
30°28'25"
68°28'43"
In the process of converting from DMS to DEC, I'd need a function to convert the string 68°28'43" (no spaces among values-symbols) into
$deg = 68
$min = 28
$sec = 43
Or something similar. Thanks
Simply use preg_match_all :)
the following regex simply captures every digits (\d) which are contains exactly 2 numbers ({2}) and group them (the braces around the expression)
<?php
$value = "68°28'43\"";
preg_match_all('/(\d{2})/', $value, $matches);
print_r($matches);
$matches would be an array with the captured results (the digits)
Array
(
[0] => Array
(
[0] => 68
[1] => 28
[2] => 43
)
[1] => Array
(
[0] => 68
[1] => 28
[2] => 43
)
)
And then you can simply assign it to your variables with the list() function as follow:
list($deg, $min, $sec) = $matches[0];
echo $deg; // 68
echo $min; // 28
echo $sec; // 43
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
I have an array
Array
(
[0] => 34
[1] => 04:32 PM
[2] => 05:32 PM
[3] => MNL | ITLY
[4] => 2h 10m
[5] => PHP 9,222
[6] => 33
[7] => 04:32 PM
[8] => 04:32 PM
[9] => ITLY | MNL
[10] => 2h 10m
[11] => PHP 7,227
)
how can i perform arithmetic operation on value of index 5 and 11.
By using preg_replace you can strip the 'PHP' part and the comma from value.
echo preg_replace('| PHP (\d+),(\d+)|', '$1$2', $array[5]) + preg_replace('| PHP (\d+),(\d+)|', '$1$2', $array[11]);
or if the number of spaces is random '\s' is any whitespace char
echo preg_replace('|\s+PHP\s+(\d+),(\d+)|', '$1$2', $array[5]) + preg_replace('|\s+PHP\s+(\d+),(\d+)|', '$1$2', $array[11]);
or str_replace()
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 want to send barcode details to a database using a PHP array and want to create tables in the database according to barcode details. for example;
barcode number: D2D6000001
Here 1st D indicates the product type, 2 indicates production line, 2nd D indicates the month, 6 indicates the year and the last 6 numbers indicate product no.
I want to send each one into separate tables in the database using a PHP array. Can someone help me with this?
try below script:
<?php
$ReciveBarcode = "D2D6000001";
$GETBARCODE = str_split($ReciveBarcode,5);
$SepratedDetails['productType'] = $GETBARCODE[0][0];
$SepratedDetails['productionLine'] = $GETBARCODE[0][1];
$SepratedDetails['month'] = $GETBARCODE[0][2];
$SepratedDetails['year'] = $GETBARCODE[0][3];
$SepratedDetails['productNumber'] = $GETBARCODE[1];
echo "<pre>";print_r($SepratedDetails);
?>
output:
Array
(
[productType] => D
[productionLine] => 2
[month] => D
[year] => 6
[productNumber] => 00001
)
Using str_split("D2D6000001") to split the value to array.
You get result some thing like Array ( [0] => D[1] => 2 [2] => D [3] => 6 [4] => 0 ) .
use substr("D2D6000001",-6) to get six digit value.
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
In a text, is it possible to find the most repeated word group with PHP ?
For example, my text is "lkjlk Star Wars jkjhyyyg h Star Wars jkhk Star Wars"
and the result will be Star Wars.
Thanks for your reply.
$string = "lkjlk Star Wars jkjhyyyg h Star Wars jkhk Star Wars";
$words = array_count_values(explode(' ', $string));
arsort($words);
var_dump($words);
that code produces the following array.
array (size=6)
'Star' => int 3
'Wars' => int 3
'jkhk' => int 1
'h' => int 1
'jkjhyyyg' => int 1
'lkjlk' => int 1
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I believe there is something like 67 million combination of two character strings using only the letters of the alphabet.
I basically want an array in PHP containing something like the following
Array
(
[1] => AA
[2] => AB
[3] => AC
[4] => AD
[5] => AE
[6] => AF
[7] => AG
[8] => AH
[9] => AI
[10] => AJ
.... and so on
)
with two loop you can do this:
<?php
$arr = array('A', 'B', 'C');
foreach ($arr as $value1) {
foreach ($arr as $value2) {
echo $value1.$value2;
}
}
?>
Then you can put the result in an array.