I am having a problem. I have a string in a variable. I split the string in to an array using explode function. But strlen function shows different lengths when I echo the string as an array element and echo the same string in strlen function. Below is my code
echo $schedule = 'Early Evening 6pm-9pm Tuesday, Early Evening 6pm-9pm Wednesday';
$scr = explode(",",$schedule);
$sc = array_map('trim', $scr);
print_r($sc);
echo strlen($sc[0]);
echo $sc[0];
echo '<br />';
echo 'string "Early Evening 6pm-9pm Tuesday" has '.strlen('Early Evening 6pm-9pm Tuesday'). ' chars<br />';
if(in_array('Early Evening 6pm-9pm Tuesday', $sc)){ echo 'yes'; } else { echo 'no'; }
and here is output:
Early Evening 6pm-9pm Tuesday, Early Evening 6pm-9pm Wednesday
Array ( [0] =>
Early Evening 6pm-9pm Tuesday [1] => Early Evening 6pm-9pm Wednesday
)
151 //length of first element of array
Early Evening 6pm-9pm Tuesday //first element of an array
string "Early Evening 6pm-9pm Tuesday" has 29 chars
no //I need yes here
I think your string contains HTML tags that you just don't see in your browser.
Try adding
$sc = array_map('htmlspecialchars', $scr);
after your third line to make them visible, or view page source of your output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.