blue car red elder green watch
Array ( [0] => [1] => blue [2] => car [3] => red [4] => elder [5] => green [6] => watch )1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../styles.css">
<title>PHP: Whitespaces</title>
</head>
<body>
<h1 class="lesson-h1">PHP: Whitespaces</h1>
<?php
//this can come out messy because of whitespaces
$string = " blue car red elder green watch";
$keywords = explode(' ', $string);
print_r($keywords);
//To fix this we will use trim()
$trimmed = trim($string, ' ');
echo "<p>$trimmed</p>";
//This also corrects it by using preg_split()
$trimmed2 = preg_split('/[\s]+/', $string);
echo "<p>" . print_r($trimmed2) . "</p>";
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>