Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Profollica™ is a standout product in the hair regrowth industry.

New Arrival!  Shop NOW for metal eyeglasses at GlassesShop.com!

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,954 questions

18,959 answers

573 users

How to find the position of the first occurrence of a substring in a string in PHP

7 Answers

0 votes
$string = 'XAMPP Control Panel';
$find   = 'Control';
$pos    = strpos($string, $find);
echo $pos;


/*
run:

6

*/

 




answered Jul 17, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = 'XAMPP Control Panel';
$find   = 'Control Power';
$pos    = strpos($string, $find);
  
if ($pos !== false)
    echo $pos;
else
    echo "string not found";


/*
run:

string not found

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = 'XAMPP Control Panel';
$find   = 'C';
$pos    = strpos($string, $find);
  
if ($pos === false)
    echo "string not found";
else
    echo $pos;


/*
run:

6

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = 'XAMPP Control Panel';
$find   = 'A';
$pos    = strpos($string, $find, 3); // srart search from char 3
  
if ($pos === false)
    echo "string not found";
else
    echo $pos;


/*
run:

string not found

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = 'XAMPP Control Panel Apache + MySQL + PHP + Perl';
$find   = 'A';
$pos    = strpos($string, $find, 3); // srart search from char 3
  
if ($pos === false)
    echo "string not found";
else
    echo $pos;


/*
run:

20

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = '1234567';
$find   = 1;  // 1 without apostrophes ''
$pos    = strpos($string, $find); 
  
if ($pos === false)
    echo "string not found";
else
    echo $pos;



/*
run:

string not found

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
0 votes
$string = '1234567';
$find   = '1'; 
$pos    = strpos($string, $find); 
  
if ($pos === false)
    echo "string not found";
else
    echo $pos;


/*
run:

0

*/

 




answered Jul 21, 2015 by avibootz
edited Jul 23, 2015 by avibootz
...