Jump to content

[SOLVED] strstr


glenelkins

Recommended Posts

From the manual:

 

Returns part of haystack string from the first occurrence of needle  to the end of haystack.

 

Thus strstr returns an empty string as there isn't anything left after .co.uk therefor use type comparison:

 

if (false !== strstr($var1, $var2)) {

Link to comment
https://forums.phpfreaks.com/topic/172803-solved-strstr/#findComment-910795
Share on other sites

i will post some example code. It makes no sense to why the strstr is not picking up the .co.uk from the first array element. The * is removed so the needle becomes .co.uk

 

$array = array ( '*.co.uk', '*.com' );

// THE ARRAY IS GENERATED FROM DATABASE SERIALIZED DATABASE VALUES. using unserialize() to create the array
// if i create the array manually then it works ok

$hostname = gethostbyaddr ( '111.111.111.111' ); // for example. server.domain.co.uk

foreach ( $array as $item ) {

    // remove the *
    // will leave .co.uk  on the first element
    $item = ltrim ( $item, '*' );

    if ( strstr ( $hostname, $item ) ) {

        die ( 'OK' );

    }

}

   

 

Link to comment
https://forums.phpfreaks.com/topic/172803-solved-strstr/#findComment-910802
Share on other sites

here ill add a bit more for the example. lets build the array from an imaginery database table

 

$result = mysql_query ( "SELECT `data` FROM `test`" );
list ( $data ) = mysql_fetch_array ( $result );

$array = unserialize ( $data );

// array ( '*.co.uk' )

 

The strstr doesnt work with this however it will work if i do:

 

$array = array ( '*.co.uk' );

 

WTF WTF WTF

 

Link to comment
https://forums.phpfreaks.com/topic/172803-solved-strstr/#findComment-910807
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.