Pioneer Skin
Login  ::  Register
Monday, February 06, 2012
 
- - - - - - - - Sponsorship Advertisement Area - - - - Thank you to our Sponsors - - - - - - - - -
Net Magik Pros - Battle Creek, Michigan Web Designers

We are please to introduce the new and improved discussion forum. It should eliminate the issues we've been having with the discusson board in the past. The old forum will still be available in "read only" mode HERE in case anyone wants to review the old topics that were posted.

WGD Forum: Discussion
Subject: Ooppss!!
Prev Next
You are not authorized to post a reply.

Author Messages
tgoodsonUser is Offline
Newbie
Newbie
Posts:32


12/09/2007 12:29 AM  

For those who are interested, I misspoke at the meeting.  The function that I was refering to find a '?' within another string is 'strpos' and not 'substr'

From the PHP manual:

strpos

Find position of first occurrence of a string (PHP 3, PHP 4, PHP 5)
int strpos ( string haystack, mixed needle [, int offset] )

 

Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos() before PHP 5, this function can take a full string as the needle parameter and the entire string will be used.

If needle is not found, strpos() will return boolean

FALSE
.

Warning:

This function may return Boolean

FALSE
, but may also return a non-Boolean value which evaluates to
FALSE
, such as
0
or "". Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

 

This is an extremely usefull function.  Hope this clears up any confusion.

tgoodsonUser is Offline
Newbie
Newbie
Posts:32


12/09/2007 1:15 PM  

Here's a piece of code that should work for the problem that Rusty was talking about.  (Basically, only allow 1 "?" in a string.)

** Tom **

---------------------------------

$string_to_test = "This is a test string? I don't know, is it?";
$once_only = "?";
$oo_pos = strpos($string_to_test, $once_only, 0);
if ($oo_pos === false)
   {
    // not found case
 echo "No question found
";
   }
else
   {
    $oo_sec = strpos($string_to_test, $once_only, $oo_pos+1);
 if ($oo_sec === false)
    {
     // Just one found
  echo "Success, found a question
";
    }
 else
    {
     // found more than one
  echo "Opps! Found more than one question
";
    }
   }
?>

You are not authorized to post a reply.



ActiveForums 3.7
Home | Membership | Events | Forum | MyPage | Login
Copyright 2007-2008 by WGD Forum :: Designed by ZapWebDesign.com