Jump to content

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 = 'USER@EXAMPLE.com';
  echo stristr($email, 'e');
// outputs ER@EXAMPLE.com
?>

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 = 'USER@EXAMPLE.com';  echo stristr($email, 'e');// outputs ER@EXAMPLE.com?>

 

 

 

thanks, that worked:

 

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

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

 

Tom

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.