newbie q -swapping incoming words in a web page - on the fly

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
charlief
Forum Newbie
Posts: 1
Joined: Mon Jun 06, 2005 11:46 pm

newbie q -swapping incoming words in a web page - on the fly

Post by charlief »

I want to be able to swap out basic words like "telephone" and " number" for their Portuguese equivalents "on-the-fly" on web pages that require a login first. It is very basic translation, I suppose, but I just need to change a few words.

My problem is that I don't know how to "capture" the results of a web page in php after data has been posted.

I have tried ob_start() and ob_end_flush and fload().And curl()

Here is my basic first attempt which actually does work (and I have read the posting code message, but I am so new I don't even know how to format this correctly. I am sorry). (Also I do have permission to adapt these web pages)

Code: Select all

<?php 


$ch = curl_init("http://208.239.76.141");

// set file to read
$file = 'http://208.239.76.141/account/login.php'; 
// read file into string 
$data = file_get_contents($file) or die('Could not read file!'); 
// print contents 
// echo $data; 


$patterns[0] = '/Login/';
$patterns[1] = '/action="/';
$patterns[2] = '/Phone/';
$replacements[0] = 'mmm clever';
$replacements[1] = 'action="http://208.239.76.141';
$replacements[2] = 'goodness';
$data =  preg_replace($patterns, $replacements, $data);
echo $data
?>
OK it is silly substitution of "Login" to "mmm clever" but it does work.


But how can I do the same "word swapping" for the results of this page after Login?

In other words can I log onto a website and still remain in a php program to manipulate the results before they reaches the users browser and if so how?

Thanks

Charlie

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

ob_start <-- read on it
is passed everything that is passed to the browser, HOWEVER be aware of chunks (unless you specify a huge size), you could get two chunks with "...tom" and "ato..." thus slipping by.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

You could store the new $file into a session variable, and call upon it when you want to display the modified login page.

What I would suggest is avoiding this whole process and in your login php have a language set which can easily be changed depending on the settings the user chooses. Store these settings in a session var and call on the database upon language changes. THis is of course if login.php belongs to you.
Post Reply