Answers for "php how to split square bracket and normal sting in a word or sentence"

PHP
0

php how to split square bracket and normal sting in a word or sentence

<?php
$format = PREG_SPLIT_DELIM_CAPTURE;
$text = "[cat]myString ";
$keywords = preg_split("/(\[[^]]+\])/", $text, -1, $format);
print_r($keywords);
echo "<br/>";
echo "First= ".$keywords[0]; output => blank 
echo "<br/>";
echo "Second= ".$keywords[1]; output => [cat]
echo "<br/>";
echo "Third= ".$keywords[2]; output => myString
?>
Posted by: Guest on March-29-2022

Code answers related to "php how to split square bracket and normal sting in a word or sentence"

Browse Popular Code Answers by Language