Skip to main content
Post Made Community Wiki by samliew
Active reading.
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

Without using an inbuilt function:-

$haystack  = "hello world";
$needle = "llo";

$i = $j = 0;

while( (isset($needle[$i]) ) {
    while( (isset($haystack[$j]) && ( $needle[$i] != $haystack[$j] )  ) {
        $j++;
        $i = 0;
    }
    if( (!isset($haystack[$j]) ) {
        break;
    }
    $i++;
    $j++;
    
}
if ( !isset($needle[$i]) ) {
        echo "YES";
} 
else{
    echo "NO ";
}

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

Without using inbuilt function:-

$haystack  = "hello world";
$needle = "llo";

$i = $j = 0;

while( isset($needle[$i]) ){
    while( isset($haystack[$j]) && ( $needle[$i] != $haystack[$j] )  ){
        $j++;
        $i = 0;
    }
    if( !isset($haystack[$j]) ){
        break;
    }
    $i++;
    $j++;
    
}
if ( !isset($needle[$i]) ){
        echo "YES";
}else{
    echo "NO ";
}

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

Without using an inbuilt function:

$haystack  = "hello world";
$needle = "llo";

$i = $j = 0;

while (isset($needle[$i])) {
    while (isset($haystack[$j]) && ($needle[$i] != $haystack[$j])) {
        $j++;
        $i = 0;
    }
    if (!isset($haystack[$j])) {
        break;
    }
    $i++;
    $j++;

}
if (!isset($needle[$i])) {
    echo "YES";
} 
else{
    echo "NO ";
}
added 458 characters in body
Source Link
Arshid KV
  • 10k
  • 3
  • 37
  • 37

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

Without using inbuilt function:-

$haystack  = "hello world";
$needle = "llo";

$i = $j = 0;

while( isset($needle[$i]) ){
    while( isset($haystack[$j]) && ( $needle[$i] != $haystack[$j] )  ){
        $j++;
        $i = 0;
    }
    if( !isset($haystack[$j]) ){
        break;
    }
    $i++;
    $j++;
    
}
if ( !isset($needle[$i]) ){
        echo "YES";
}else{
    echo "NO ";
}

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){

    echo "true";
}

Without using inbuilt function:-

$haystack  = "hello world";
$needle = "llo";

$i = $j = 0;

while( isset($needle[$i]) ){
    while( isset($haystack[$j]) && ( $needle[$i] != $haystack[$j] )  ){
        $j++;
        $i = 0;
    }
    if( !isset($haystack[$j]) ){
        break;
    }
    $i++;
    $j++;
    
}
if ( !isset($needle[$i]) ){
        echo "YES";
}else{
    echo "NO ";
}
added 39 characters in body
Source Link
Arshid KV
  • 10k
  • 3
  • 37
  • 37

You can use the strposstrstr function:

$str$haystack = "I want aknow job";programming";
$needle   = "know";
if$flag (strpos= strstr($str$haystack, 'job'$needle) !==;

if false($flag) { 

    echo 'true';"true";
}

You can use the strpos function:

$str = "I want a job";

if (strpos($str, 'job') !== false) {
    echo 'true';
}

You can use the strstr function:

$haystack = "I know programming";
$needle   = "know";
$flag = strstr($haystack, $needle);

if ($flag){ 

    echo "true";
}
added 10 characters in body
Source Link
Arshid KV
  • 10k
  • 3
  • 37
  • 37
Loading
Copy edited (e.g. ref. <http://english.stackexchange.com/questions/4645/is-it-ever-correct-to-have-a-space-before-a-question-or-exclamation-mark#comment206109_4645>).
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134
Loading
Source Link
Arshid KV
  • 10k
  • 3
  • 37
  • 37
Loading