Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

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
?>
 
PREVIOUS NEXT
Tagged: #php #split #square #bracket #normal #sting #word #sentence
ADD COMMENT
Topic
Name
1+4 =