Jump to content

help finding string in a string e.g. STRIPOS()


tcloud

Recommended Posts

I need to know if a string exists within a string.

 

I've tried using STRIPOS() but it returns zero or false if what I'm looking for is the first part of the string.

 

I don't care what function I use, but I need to get a "true" when the needle string is present anywhere in the haystack string, even at location zero.

 

Is there some way to set up the STRIPOS() statement?

 

I've tried:

 

 

if ((stripos($title, 'needle') > 0 )
if ((stripos($title, 'needle') = true )

and even

if ((stripos($title, 'needle') >= 0 )

which returns true for everything, even when the needle string is NOT present.

 

Any help appreciated.

 

thanks,

Tom

maybe try stristr:

 

 

stristr

 

(PHP 3 >= 3.0.6, PHP 4, PHP 5)

 

stristr --  Case-insensitive strstr()

Description

 

string stristr ( string haystack, string needle )

Returns all of haystack from the first occurrence of needle to the end. needle and haystack are examined in a case-insensitive manner.

 

If needle is not found, returns FALSE.

 

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

 

Example 1. stristr() example

<?php
  $email = '[email protected]';
  echo stristr($email, 'e');
// outputs [email protected]
?>

maybe try stristr:

 

 

stristr

 

(PHP 3 >= 3.0.6, PHP 4, PHP 5)

 

stristr --  Case-insensitive strstr()

Description

 

string stristr ( string haystack, string needle )

Returns all of haystack from the first occurrence of needle to the end. needle and haystack are examined in a case-insensitive manner.

 

If needle is not found, returns FALSE.

 

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character.

 

Example 1. stristr() example

 

<?php  $email = '[email protected]';  echo stristr($email, 'e');// outputs [email protected]?>

 

 

 

thanks, that worked:

 

if (stristr($title, 'needle') == true)

works properly even if "needle" is at the beginning of the string.

 

Tom

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.