can anyone helping me to showing first name/word on navigation? i’ve trying this code
<div class="d-sm-none d-lg-inline-block">Welcome, <?php $string = $this->session->userdata('name'); echo $firstCharacter = $string[0]; ?></div></a>
but this code only showing the first character. i mean like if my name george bush then it only get “Welcome, g”. i want to showing more like “Welcome, george” without bush. how to do it?
sorry for my bad english and i’m new to php things. and thanks for helping me before
Advertisement
Answer
You could use regular expressions, like this:
echo preg_replace('/^([^s]+)s*.*$/', '$1', $string);
or split it:
echo (explode(' ', $string))[0]
;
or ‘tok’ it:
echo strtok($string, " ")