Create javascript friendly string from PHP

Закрито Опубліковано %project.relative_time Оплачується при отриманні
Закрито Оплачується при отриманні

I've recently written a PHP script that downloads a webpage, and then creates the javascript code to display that webpage.

That way, I can do something like this:

So it downloads the page, and then wraps each line in [url removed, login to view]().

Here is the script:

$url = $_GET["url"];

$file = file("$url");

for($i = 0; $i < count($file); $i++)

{

$line = $file[$i];

$line = substr($line, 0, strlen($line)-1); // removes the new line character

$line = addslashes($line);

$str = "[url removed, login to view](\"$line\");\n";

print($str);

}

The problem is that it doesn't work on every web page... For example, it works with [url removed, login to view], but not [url removed, login to view], or most others.

My guess is that PHPs addslashes does not escape the proper characters to generate a javascript friendly string.

Could somebody help me get this script working? It's very urgent, and I'll need it finished within an hour or two of the project acceptance.

## Deliverables

1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.

2) Deliverables must be in ready-to-run condition, as follows (depending on the nature of the deliverables):

a) For web sites or other server-side deliverables intended to only ever exist in one place in the Buyer's environment--Deliverables must be installed by the Seller in ready-to-run condition in the Buyer's environment.

b) For all others including desktop software or software the buyer intends to distribute: A software installation package that will install the software in ready-to-run condition on the platform(s) specified in this bid request.

3) All deliverables will be considered "work made for hire" under U.S. Copyright law. Buyer will receive exclusive and complete copyrights to all work purchased. (No GPL, GNU, 3rd party components, etc. unless all copyright ramifications are explained AND AGREED TO by the buyer on the site per the coder's Seller Legal Agreement).

* * *This broadcast message was sent to all bidders on Tuesday Mar 15, 2005 11:19:37 AM:

I actually solved my problem early last night, before the project was approved. I think the problem was on that line where I stripped off the newline character. I changed it so that I now just strip off all \r and \n, and it seems to work well. Then, I had to output a line giving it a new base href, so that the images with relative paths would work...

Now the only problem is that google adsense ads, and several other third party scripts are not downloading.... I thought that it might be because I myself was acting as a third party, because I was downloading the remote page and displaying it... but then I realized that all google adsense ads are served to a third party, so that wasn't the problem. To double check, I checked my logs and googles '[url removed, login to view]' actually was being downloaded, it just wasn't being displayed properly.

I know that javascript c an be used to display and render other javascript, because I've tested it with a simple hello world. Perhaps the problem is just that it can't create new variables, and googles script uses several variables...

Perhaps there is a solution using javascript's eval()?

When asking around in forums, somebody said this:

> Many sites use redirects all over the

> place, so you might be better off

> using CURL instead of file(). Some

> are picky about user agents too, so

> you could try pretending to be IE.

Could you give an example as to how to do these things? I was thinking about both of those problems last night, and after some research it seemed like the solution was to use psocketopen, and then write a custom user-agent and referer header when requesting the file.

* * *This broadcast message was sent to all bidders on Tuesday Mar 22, 2005 1:34:07 PM:

Here is the current version of the script ([url removed, login to view]). What I'm trying to do is get google adsense ads and other third party scripts to display correctly:

$url = $_GET["url"];

$lines = file($url);

for($i = 0; $i < count($lines); $i++)

{

$line = $lines[$i];

$line = str_replace("\n", "", $line);

$line = str_replace("\r", "", $line);

$line = addslashes($line);

print("[url removed, login to view](\"$str\");\n");

}

* * *

Alright, the original problem I was having was the line where I strip off the last character on the line. I changed it so that it just strips all \n and \r from the string, and that solved a lot of problems.

Then I noticed that any image that is using a relative path for it's source was not being displayed. That is because the images do not reside on my server. So to solve that problem, I added a line changing the document base, something l ike this:

No my problem seems to be when there is already javascript on the page I'm trying to 'embed'. It works fine with simple scripts, and I tested it with a simple hello world javascript. But the problems are with google adsense, and other remotely hosted scripts. I believe the problem is when the scripts need to create new variables. This is in short what I'm trying to do:

[url removed, login to view](" ");

And it's not working... I think that the solution may need to copy all embedded javascript code into it's own function in the 'higher level' script... so it would output something like this:

function doScript1

{

var temp = "hi";

[url removed, login to view](temp);

}

[url removed, login to view](" ");

I'm not sure if there is another solution, or if this would work. I'm willing to change the maximum bid if somebody thinks that they can come up with a solution.

## Platform

php, javascript

Техніка JavaScript MySQL Odd Jobs PHP Архітектура ПЗ Тестування ПЗ Тестування / QA Юзабіліті-тестування Веб-хостинг Управління веб-сайтами Тестування сайтів

ID Проекту: #3611838

Про проект

6 заявок(-ки) Дистанційний проект Остання активність Jul 3, 2005

6 фрілансерів(-и) готові виконати цю роботу у середньому за $6

adzzeit

See private message.

$4.25 USD за 1 день
(12 відгуків(и))
3.6
idsvw

See private message.

$8.5 USD за 1 день
(15 відгуків(и))
3.6
vw1460069vw

See private message.

$3.4 USD за 1 день
(20 відгуків(и))
3.5
svenneumannvw

See private message.

$4.25 USD за 1 день
(0 відгуків(и))
0.0
vw1470172vw

See private message.

$8.5 USD за 1 день
(1 відгук)
0.0
celestialsvw

See private message.

$8.5 USD за 1 день
(1 відгук)
0.0