PHP mb_ereg_search_setpos() Function
Last Updated :
26 Apr, 2023
The mb_ereg_search_setpos() function is an inbuilt function in PHP that is used for setting the starting point for the next regular expression that will be matched.
Syntax:
mb_ereg_search_setpos(int $offset): bool
Parameter: This function accepts one parameter that is described below.
- $offset: This parameter is integer type if this parameter value is positive, it will start from the beginning, or if the negative value it will start from the end of the string.
Return Values: This function returns “true” if the function successfully executes otherwise it will return “false”.
Example 1: The following code demonstrates the mb_ereg_search_setpos() function.
PHP
<?php
$pos = 5;
mb_ereg_search_setpos( $pos );
$str = "Her Number is 993459" ;
mb_ereg_search_init( $str );
if (mb_ereg_search( "test" )) {
echo "Match found!" ;
} else {
echo "Match not found." ;
}
?>
|
PHP
<?php
$pos = 5;
mb_ereg_search_setpos( $pos );
$str = "Her Number is 993459" ;
mb_ereg_search_init( $str );
if (mb_ereg_search( "test" )) {
echo "Match found!" ;
} else {
echo "Match not found." ;
}
?>
|
Output:
Match not found!
Example 2: The following program demonstrates mb_ereg_search_setpos() function
PHP
<?php
$pos = 2;
mb_ereg_search_setpos( $pos );
$str = "This is a 9334 Number." ;
mb_ereg_search_init( $str );
echo mb_ereg_search( "Number" )
?>
|
Output:
1
Reference: https://www.php.net/manual/en/function.mb-ereg-search-setpos.php
Share your thoughts in the comments
Please Login to comment...