UKTSLiam UKTSLiam - 5 months ago 8
PHP Question

How to check and get different part of a string

I'm looking to have it so someone does !whisper EXAMPLE this is a test example.

It would output

$whisperuser
as "EXAMPLE" &
$whispermessage
as "this is a test example".

<?php
if (strpos($message, '!whisper') === 0) {
$arr = explode(' ',trim($message));
$whisperuser = $arr[1];
$whispermessage = $arr[2]; // I need Whisper message to be anything arr[2] and HIGHER.
// WOULD DO OUTPUT STUFF HERE
}
?>

Answer

Your code can be written easy. After adding the 3rd argument to explode, it will put the rest of a string to the last item

list( , $whisperuser, $whispermessage) = explode(' ',trim($message), 3);

demo

Comments