Forum Moderators: coopster
The file is stored in a tmp folder, so I will use fopen but then, what function can I use so that I can store the X's numbers in $numbers variable and then delete the file?
Edit: I see the X's were replaced with #*$!#*$!#*
[url=http://uk.php.net/manual/en/function.preg-match.php]preg_match[/url]('%number=(\d){10}%', $input, $match)
'%number\s?=\s?(\d){10}%i'
$file = '/home/something/else/filetmp';
$handle = fopen($file, "r");
$input = fread($handle, filesize($file));
fclose($handle);
$pattern = '[0-9]{10}';
ereg($pattern,$input,$regs);
$session = $regs[0]; // Now I have the 10 digits number stored in $session
Can you spot any mistake in the code? Is fclose() in the right location so that the file is indeed closed?
The code does work as I expected, but maybe it's more efficient to use the method PHP_Chimp described, with preg_match() so I will be testing it. Thanks again for your answers.
Edit: used [ code ] tag for code formatting
ereg is slower than preg_*. So generally there is no advantage to using ereg over something like preg_match. However the speed difference with most of these things is fractions of a millisecond...so faster may well not be something that you actually notice.
The biggest advantage of preg_* is that it is PERL compatible regular expressions, so there is a lot more you can do with preg than you can with ereg. Like the fact you can use the pre-built character classes, like \d ;)