Reading Characters
Moderator: General Moderators
Reading Characters
I've just moved from Vbasic to PHP. At the moment I am trying to make a script that will check to see if a '#' is in a variable. Basically I'm looking for a function like fgetc but for variables.
Any help would be greatly appreciated.
Desinc
Any help would be greatly appreciated.
Desinc
The function you're looking for is
That will return true/false if the string was found/not found.
Go to http://ca2.php.net/strings for many more useful string functions.
Code: Select all
strstr($what_youre_looking_for,$what_youre_looking_in)Go to http://ca2.php.net/strings for many more useful string functions.
File_get_contents will put the file into a single string. File will put each line in a new element in an array. If you're just getting '0', I would imagine it's a result of a read in error. Maybe post some code so I can make a more educated guess 
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Fine.. you asked for it. ;p
Code: Select all
<?php
//Delcare Varables
$userdatabase = "0";
$newaccount = "0";
//Delcare Varables
echo $userdatabase; //For Debugging
$userdatavase= file_get_contents("userdatabase.txt");
echo $userdatabase; //For Debugging
if (strstr($userdatabase,$_POST["requsername"] ))
{
echo "The username" . $_POST["requsername"] . "has already been taken";
}
?>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Not sure if it was intentional, but "$userdatabase" is spelled wrong in this line:
Probably should be:
Which would explain why it echos "0" 
Code: Select all
<?php
$userdatavase= file_get_contents("userdatabase.txt");
?>Code: Select all
<?php
$userdatabase = file_get_contents("userdatabase.txt");
?>