Skip to content
Advertisement

How to get the first word of a sentence in PHP?

I want to extract the first word of a variable from a string. For example, take this input:

JavaScript

The resultant output should be Test, which is the first word of the input. How can I do this?

Advertisement

Answer

You can use the explode function as follows:

JavaScript

Another example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement