What is the Php function for string contain?

0 votes
asked Jun 21, 2013 in Php by Sonali Srinivas

What is the function in php to find a string which contains another string? I tried to find strcontain() function same as strlen(), but not available in php. Is there a method to find matching string or we need another methodology like regular expression to find it. I hope php should have some built in function to do this. Please post me sample ASAP.

Share

2 Answers

+1 vote
answered Jul 16, 2013 by Priya Roy (122 points)
selected Jul 18, 2013 by administrator
 
Best answer

you can use strops function to find a string in php.

example

$x = "Hi priya how are you";

Now you want to find the string priya from the above variable $x

then use something like below.

if (strpos($x,'priya') !== false) {
    echo 'true';
}
0 votes
answered Jul 28, 2016 by Thomasf (54 points)

You could use an offset too:

<?php
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>

Your answer

Preview

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2015 pinfaq.com
...