php uses the explode function to split strings into arrays
- 2020-12-26 05:36:34
- OfStack
Split string
// Use the explode function to split strings into arrays
//split function for character segmentation
The // separator can be a slash, dot, or horizontal line
Through the array to achieve multi - conditional query code
// Use the explode function to split strings into arrays
<?php
$source = "hello1,hello2,hello3,hello4,hello5";// Separate the strings by commas
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++)
{
echo $hello[$index];echo "</br>";
}
?>
//split function for character segmentation
The // separator can be a slash, dot, or horizontal line
<?php
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
Through the array to achieve multi - conditional query code
<?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;