Page 1 of 1

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

Posted: Tue Jun 07, 2005 12:13 am
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]

Posted: Tue Jun 07, 2005 7:16 am
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.

Posted: Tue Jun 07, 2005 9:31 am
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.