assigning html code to a variable
Moderator: General Moderators
assigning html code to a variable
hi, I'm pretty new to php, and this is probably a simple question. what I'm trying to do is manipulate source code of a website to display only the part of the code I want it to display. so I'm planning to assign the code of a website to a variable, then play around with that variable until it only shows what I want. I know there is a way to assign the results/source code of a website to a variable, I just forget how. can someone help me out! thanks.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I certainly hope you have permission to do this.
Anyways, depending on settings, file_get_contents() can request a page, so can file(), curl and fsockopen(), among other things.
Anyways, depending on settings, file_get_contents() can request a page, so can file(), curl and fsockopen(), among other things.
There are all kinds of methods to do this...
You can read from a file...
Another file reading method...
How about putting the file, into array, each element is a single line terminated by \r?\n
Have a look at PHP FILE FUNCTIONS, they should help you do what you want!
pif!
You can read from a file...
Code: Select all
//put the contents of some_file.txt in the variable $data
$data = fread ( fopen ( 'some_file.txt', 'rb' ), filesize ( 'some_file.txt' ) );
echo $data;Code: Select all
//put the contents of local_file.txt in the variable $data
$data = file_get_contents ( './local_file.txt' ); // can fetch URL(s) to
echo $data;How about putting the file, into array, each element is a single line terminated by \r?\n
Code: Select all
//put the contents of local_file.txt in the variable $data = array ();
$data = file ( 'local_file.txt' );
print_r ( $data );Have a look at PHP FILE FUNCTIONS, they should help you do what you want!
pif!