Split string
Using the explode function to split a string into an array
Copy the code code as follows:
<?php
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separate strings by commas
$hello = Explode (', ', $source);
for ($index =0; $index <count ($hello); $index + +)
{
echo $hello [$index];echo "</br>";
}
?>
Split function for character segmentation
The delimiter can be a slash, a dot, or a horizontal line
Copy the code code as follows:
<?php
$date = "04/30/1973";
List ($month, $day, $year) = Split (' [/.-] ', $date);
echo "Month: $month; Day: $day; Year: $year <br/>\n ";
?>
Code to implement a multi-condition query through an array
Copy the code code as follows:
<?php
$keyword = "asp php,jsp";
$keyword =str_replace ("", "", $keyword);
$keyword =str_replace ("", ",", $keyword);
$keyarr =explode (', ', $keyword);
for ($index =0; $index <count ($keyarr); $index + +)
{
$whereSql. = "and (Arc.title like '% $keyarr [$index]% ' Or arc.keywords like '% $keyarr [$index]% ')";
}
Echo $whereSql;
PHP string Split output