Sarkar
Sarkar

Reputation: 79

Add double quote to a string

How can I add double quote to this string. The string I have

01-08-2022,02-08-2022,04-08-2022,05-08-2022,06-08-2022,14-08-2022

The string I want

"01-08-2022","02-08-2022","04-08-2022","05-08-2022","06-08-2022","14-08-2022"

Upvotes: -1

Views: 257

Answers (2)

jspit
jspit

Reputation: 7703

As an alternative to CBroe's solution in the comment, you can also work with str_replace:

$str = '01-08-2022,02-08-2022,04-08-2022,05-08-2022,06-08-2022,14-08-2022';

$str = '"'.str_replace(',','","',$str).'"';

echo $str;
//"01-08-2022","02-08-2022","04-08-2022","05-08-2022","06-08-2022","14-08-2022"

Upvotes: 0

prashant
prashant

Reputation: 36

Try with using explode and implode method as below

$oldString = '01-08-2022,02-08-2022,04-08-2022,05-08-2022,06-08-2022,14-08-2022';
$newString = sprintf('"%s"', implode('","', explode(',', $oldStr)));
echo $newString;

Upvotes: 1

Related Questions