How to get the word of a sentence in PHP?


Example 1

<?php

$pizza  "piece1 piece2 piece3 piece4 piece5 piece6";

$pieces explode(" "$pizza);
echo 
echo $pieces[0]// piece1
echo $pieces[1]// piece2
?>

output:
piece1 piece2

Example 2

<?php
$myvalue = 'Test me more';
$arr = explode(' ',trim($myvalue));
echo $arr[1]; // will print Test
?>
output: me

About the Author

Expert writer helping professionals grow their knowledge through well-researched content and strategic insights.

Read the previous article

Popular Posts