strpbrk 


string apg

SEARCH a string for any of a set of characters by the case-sensitive way.





This function returns a STRING starting from the character found, or FALSE if it is not found.



<?php

str strpbrk 
( str $haystack , str $char_list )


where,

$haystack = The STRING where char_list is looked for

$char_list = The list of characters

?>
 

$str


The STRING where $char_list is looked for.



$char_list


The list of characters.



  1 EXERCISE   

<?php

$par01 
= 'Vir Bonus Dicendi Peritus!';

$list01 = 'usB';

$str01 = strpbrk($par01, $list01);

if (
$str01)
{
echo 
"List of characters:<br>$list01 
<br><br>Is Found in:<br>
$str01";
}
else
{
echo 
"No character of $list01 
<br>was found on<br>
$par01";
}

?>

  2 EXERCISE   

<?php

$par02 
= 'Vir Bonus Dicendi Peritus!';

$list02 = 'SCENE';

$str02 = strpbrk($par02, $list02);

if (
$str02)
{
echo 
"List of characters:<br>$list02 
<br><br>Is Found in:<br>
$str02";
}
else
{
echo 
"No character of $list02 
<br>was found on<br>
$par02";
}

?>

  3 EXERCISE   

<?php

echo "Testing strpbrk() : basic functionality.
<br>- - - - - - -<br>"
;

function 
str_pbrk($one, $two) {
    echo 
"<br>$one<br>and<br>$two<br><br>Returned value:<br>";
    
var_dump(strpbrk($one, $two));
    echo 
'<br>- - - - - - -<br>';
}  

// Initialise all required variables
$text = 'This is a Simple text.';
str_pbrk($text, 'mi');
str_pbrk($text, 'ZS');
str_pbrk($text, 'Z');
str_pbrk($text, 'H');

$text = '';
str_pbrk($text, 'foo');

$text = "  aaa aaaSLR";
str_pbrk($text, '     ');

str_pbrk(5, 5);
str_pbrk(5, "5");

?>

  4 EXERCISE   

<?php

$haystack 
= 'This is a Simple text.';

echo 
"Testing strpbrk() 
            function with empty second argument.<br><br>"
;
try {
    
strpbrk($haystack, '');
} catch (
\ValueError $e) {
    echo 
$e->getMessage() . "<br>";
}

?>