-3
I need to quote at the beginning and end of each number.
Example:
I have the following sequence:
$seq = "123,456,789";
the result would have to stay like this
$seq = "'123','456','789'";
-3
I need to quote at the beginning and end of each number.
Example:
I have the following sequence:
$seq = "123,456,789";
the result would have to stay like this
$seq = "'123','456','789'";
2
You can also make a Explode, Map and then Implode to transform, I will send below the example:
$myNumbers = "123,456,778";
$myNumbersExploded = explode(",", $myNumbers);
$myNumbersWithNewCaracter = array_map(function($v){ return "'".$v."'"; }, $myNumbersExploded);
$myNumbers = implode(",", $myNumbersWithNewCaracter);
var_dump($myNumbers);
Exit below:
hit the variable in var_dump and took advantage put your example in ideone
Thank you @Leocaracciolo!
0
Another way of doing:
$seq = "123,456,789";
$explode_seq = explode(',', $seq);
$n = array();
foreach ($explode_seq as $num){
$n[] = "'" . $num . "'";
}
$result = implode(" , ", $n);
echo $result;
0
You can concatenate the single quote at the beginning and end of the string and replace the comma "," by " ',' " (single quote + comma + single quote) using php’s substr_replace.
http://php.net/manual/en/function.substr-replace.php.
Any doubt post there for us to see.
0
You can use explode()
function colocaAspas($n){ return "'".$n."'"; }
$seq = "123,456,789";
$seq = array_map('colocaAspas', explode(',', $seq));
var_dump($seq);
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
And how did you try to do it? What was the result obtained?
– Woss