Find Jobs
Hire Freelancers

Create javascript friendly string from PHP

$5-10 USD

Cerrado
Publicado hace alrededor de 19 años

$5-10 USD

Pagado a la entrega
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 del proyecto: 3611838

Información sobre el proyecto

6 propuestas
Proyecto remoto
Activo hace 19 años

¿Buscas ganar dinero?

Beneficios de presentar ofertas en Freelancer

Fija tu plazo y presupuesto
Cobra por tu trabajo
Describe tu propuesta
Es gratis registrarse y presentar ofertas en los trabajos
6 freelancers están ofertando un promedio de $6 USD por este trabajo
Avatar del usuario
See private message.
$4,25 USD en 1 día
4,8 (12 comentarios)
3,6
3,6
Avatar del usuario
See private message.
$8,50 USD en 1 día
5,0 (15 comentarios)
3,6
3,6
Avatar del usuario
See private message.
$3,40 USD en 1 día
4,9 (20 comentarios)
3,5
3,5
Avatar del usuario
See private message.
$4,25 USD en 1 día
0,0 (0 comentarios)
0,0
0,0
Avatar del usuario
See private message.
$8,50 USD en 1 día
0,0 (1 comentario)
0,0
0,0
Avatar del usuario
See private message.
$8,50 USD en 1 día
0,0 (1 comentario)
0,0
0,0

Sobre este cliente

Bandera de UNITED STATES
United States
5,0
5
Miembro desde jul 23, 2004

Verificación del cliente

¡Gracias! Te hemos enviado un enlace para reclamar tu crédito gratuito.
Algo salió mal al enviar tu correo electrónico. Por favor, intenta de nuevo.
Usuarios registrados Total de empleos publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Cargando visualización previa
Permiso concedido para Geolocalización.
Tu sesión de acceso ha expirado y has sido desconectado. Por favor, inica sesión nuevamente.