How to use explode() function In PHP
In this approach, we are using the explode() function in PHP which is used to split a string into an array based on a specified delimiter. Here we use a space character as the delimiter to split the string into words.
Syntax:
words = explode(delimiter, string);
Example: This example uses explode() function to extract words from given string.
<?php
$string = "Welcome to w3wiki";
$words = explode(" ", $string);
print_r($words);
?>
Output
Array ( [0] => Welcome [1] => to [2] => w3wiki )
How to Extract Words from given String in PHP ?
Extracting words from a given string is a common task in PHP, often used in text processing and manipulation.
Below are the approaches to extract words from a given string in PHP:
Table of Content
- Using explode() function
- Using regular expressions
Contact Us