Jump to content


Photo

[solved]quistion about strpos


  • Please log in to reply
3 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 August 2006 - 12:11 AM

Does strpos mean stringpostion?

can some one post more examples please cheers.

i did read the manual cheers still dont understand the format of the code.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 12:17 AM

yes it means string postion

and i think it would mean where the string is in the string
<?php
$mystring = 'abc';
$findme  = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
   echo "The string '$findme' was not found in the string '$mystring'";
} else {
   echo "The string '$findme' was found in the string '$mystring'";
   echo " and exists at position $pos";
}

// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?> 


#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 August 2006 - 12:40 AM


why this wrong please cheers


<?php

$word="my name is redarrow";

$badword=array("redarrow");

foreach($badword as $b){

if($bad=strpos($b,$word)){

$bad=="yes";

brake;
}
}

if($bad=="yes"){

echo " sorry bad word";
}else{
echo "good word";
}

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 August 2006 - 12:52 AM

solved cheers.
<?php

$word="my name is redarrow";

$badword=array("redarrow");

foreach($badword as $b){

$bad=strpos($word,$b);

}

if($bad==true){

echo " sorry bad word";

}else{

echo "good word";
 
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users