Help me on string functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
magosla2001
Forum Newbie
Posts: 20
Joined: Sat May 20, 2006 8:54 am

Help me on string functions

Post by magosla2001 »

I am having problems with some strings functions;
strpos()
strstr()
strrpos()
substr()
strcmp()

When they are been executed from my local server but haventh been tested with a shared hosting, the result desplayed on my browser is;
Warning: Wrong parameter count for substr()
BELOW is a sample of the code i wrote to test the string functions
<?
$short = "This string Has 29 Characters";
for($i = 0; $i < strlen($short); $i++){
printf($short{$i});
}
$sts = "s";
print("The position of $sts in $short is:". strpos($short. $sts));
print("Result of looking for $sts". strstr($short. $sts));
echo substr("dkfhs fsd fkdhf sdfkds fsd sd sdhf sdhf sdfsdf" . 12 . 24);
?>


AND below was the result desplayed in my browser
This string Has 29 Characters
Warning: Wrong parameter count for strpos() in E:\Softwares\xampplite\htdocs\test\str.php on line 10
The position of s in This string Has 29 Characters is:
Warning: Wrong parameter count for strstr() in E:\Softwares\xampplite\htdocs\test\str.php on line 11
Result of looking for s
Warning: Wrong parameter count for substr() in E:\Softwares\xampplite\htdocs\test\str.php on line 12
So I want sombody to help me in this as in where I go wrong.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

your periods in between the parameters on your str* calls should be commas.

That is:

Code: Select all

<?
$short = "This string Has 29 Characters";
for($i = 0; $i < strlen($short); $i++){
printf($short{$i});
}
$sts = "s";
print("The position of $sts in $short is:". strpos($short, $sts));
print("Result of looking for $sts". strstr($short, $sts));
echo substr("dkfhs fsd fkdhf sdfkds fsd sd sdhf sdhf sdfsdf", 12, 24);
?> 
magosla2001
Forum Newbie
Posts: 20
Joined: Sat May 20, 2006 8:54 am

Post by magosla2001 »

Thank for your help, The problem has been resolved
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

Spectacularific!
Post Reply