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 have array:
$array = array(
'/news/show/([0-9])/([0-9])'=>'/news/show/id/$1/id2/$2',
'/home/ayz/([0-9])'=>'/home/xyz/sid/$1'
);
I want result:
$array = array(
'/news/show/$1/$2'=>'/news/show/id/([0-9])/id2/([0-9])',
'/home/ayz/$1'=>'/home/xyz/sid/([0-9])'
);
How to do it??
$aReplace = array('$1'=>'([0-9])','$2'=>'([0-9])');
$aNewArray = array();
foreach ($array as $key=>$value){
$nKey = str_replace(array_values($aReplace), array_keys($aReplace),$key);
$nValue = str_replace(array_keys($aReplace), array_values($aReplace),$value);
$aNewArray[$nKey]=$nValue;
}
Related
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
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }
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 receive data in this format like:
C00001,C00302,C00303,C00287,C00286,C00285,C00017
in a variable but i need in this shape:
'C00001','C00302','C00303','C00287','C00286','C00285','C00017'
i am new in mysql kindly any help
You can explode the data, modify it, then re-implode it.
$data = 'C00001,C00302,C00303,C00287,C00286,C00285,C00017';
$arr = explode(',', $data);
$new_arr = array_map(function($a){
return "'{$a}'";
}, $arr);
$new_data = implode(',', $new_arr);
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 have a string input using PHP that look like this:
Log,,t1,12.12:t2,20.23:t3,30.00:t4,50.20:11.23
I want to save it into MySQL
field:reading
t1:12.12
t2:20.23
t3:30.00
t4:50.20
Temp:11.23
Can anyone give me an direction?
Begin you have to parse to rows and columns
$string = 't1,12.12:t2,20.23:t3,30.00:t4,50.20:11.23';
$rows = explode(':', $string);
$table = array();
foreach(rows as $row) {
$table[] = explode(',', $row);
}
You can use regex below:
if (preg_match_all('/[a-z]+\d+,\d+\.\d+|\d+\.\d+/i', $string, $matches) {
var_dump($matches[0]);
}
The regex can be a bit simpler if each field will called "t+number":
if (preg_match_all('/t\d+,\d+\.\d+|\d+\.\d+/i', $string, $matches) {
var_dump($matches[0]);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
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
Improve this question
I have an array that depending of my input, will return different name for a particular node. For example below I the name of the key node is n1:ModemProduct1207 but it could be also n1:ModemProduct1308.
I was wondering is there is a way to have something like this:
$array ['n1:ModemProducts'] ['n1:ModemProduct'. (regex here like"n1:ModemProduct[\d0-9]{4}+")];
$modemProducts = $array ['n1:ModemProducts'] ['n1:ModemProduct1207'];
I tried couple of options but could not get it to work.
Little function for one-dimensional array:
function filterProducts($array, $pattern){
$result = array();
foreach($array as $key => $value){
if (preg_match($pattern, $key)){
$result[$key] = $value;
}
}
return $result;
}
Usage:
$results = filterProducts($array['n1:ModemProducts'], '/n1:ModemProduct[\d]{4}/');
$array = array('Armenia', 'America', 'Algeria', 'India', 'Brazil', 'Croatia', 'Denmark');
$fl_array = preg_grep('/^A.*/', $array);
print_r($fl_array);
for referance you can see . http://ask.amoeba.co.in/php-search-in-an-array-for-values-matching-a-pattern-regex-wildcard/
I am Trying to solve your problam
Hope this Help
Thanks
Anand
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
$a='Would you like to have responses to your questions sent to you via email'
for($a as $b=>c){
}
Kindly give me the solution
<?php echo substr_count($a, 't'); ?>
Here's a solution, though not necessarily the best
$letterCount = array_count_values(
str_split(strtolower($a))
);
$tCount = (isset($letterCount['t'])) ? $letterCount['t'] : 0;
$count = preg_match_all('/t/', $str);
check this one
<?php
$a = 'Would you like to have responses to your questions sent to you via email';
$t_explod = explode('t', strtolower($a));
echo count($t_explod) - 1;
?>