Find Jobs
Hire Freelancers

Create javascript friendly string from PHP

$5-10 USD

已关闭
已发布大约 19 年前

$5-10 USD

货到付款
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 [login to view URL](). 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 = "[login to view URL](\"$line\");\n"; print($str); } The problem is that it doesn't work on every web page... For example, it works with [login to view URL], but not [login to view URL], 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 '[login to view URL]' 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 ([login to view URL]). 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("[login to view URL](\"$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: [login to view URL](" "); 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"; [login to view URL](temp); } [login to view URL](" "); 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
项目 ID: 3611838

关于此项目

6提案
远程项目
活跃19 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
6威客以平均价$6 USD来参与此工作竞价
用户头像
See private message.
$4.25 USD 在1天之内
4.8 (12条评论)
3.6
3.6
用户头像
See private message.
$8.50 USD 在1天之内
5.0 (15条评论)
3.6
3.6
用户头像
See private message.
$3.40 USD 在1天之内
4.9 (20条评论)
3.5
3.5
用户头像
See private message.
$4.25 USD 在1天之内
0.0 (0条评论)
0.0
0.0
用户头像
See private message.
$8.50 USD 在1天之内
0.0 (1条评论)
0.0
0.0
用户头像
See private message.
$8.50 USD 在1天之内
0.0 (1条评论)
0.0
0.0

关于客户

UNITED STATES的国旗
United States
5.0
5
会员自7月 23, 2004起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。