shlagish
06-05-2004, 04:36 AM
How can I take the content of a text file and store it in a variable?
What I ultimatly want to do is take that variable, extract what I want with regular expression and write that out..
So if you could also point me to some good regular expression tutorial, that would be great.
litebearer
06-05-2004, 04:38 AM
try using fread
http://www.php.net/fread
shlagish
06-05-2004, 04:39 AM
I don't understant fread, why do I have to give the filesize and stuff? Why can't I just read the whole file?
shlagish
06-05-2004, 04:53 AM
Here is the code I got.
<html>
<body>
<?php
$handle=fopen('glossary.txt', 'r');
$string=fread($handle,99999999);
fclose($handle);
echo($string);
?>
</body>
</html>
How would I now use regular expression for get only te desired part of the text file?
my text file contains this:
-------------
<table>
<tr id="someID"><td>G</td><td>word</td></tr>
<tr id="anotherID"><td>U</td><td>yay</td></tr>
...
</table>
-------------
I want to make a function like this:
function getWord($word){
$handle=fopen("glossary.txt");
$string=fread("$handle,99999999);
fclose($hadle);
$newString=regexp($string) //This should give me:
"<tr id="$word"><td>*</td><td>*</td></tr>"
echo($newString);
}
I might me mixing up with javascript syntax, but what I really want is to get starting tips and maybe links about PHP regular expression, I'll figure the rest out from there :)
carl_mcdade
06-05-2004, 07:13 AM
What I think is the best and most understandable tutorial on Regex on the net.
http://www.regular-expressions.info