🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #2904

Re: Ayuda: Vaciar resultado de un PHP a un archivo de texto

#2904
From: Cristian Gutierrez
Date: Thu, 14 Jul 2005 00:03
38 lines
3438 bytes
Hoy en la tarde, Cristian Allendes V. dijo:
> Ojala y alguien me pueda ayudar.
>
> Tengo un archivo PHP que se conecta a una base de datos y el resultado
> es una pagina web completa (con imagenes, texto, urls, etc.)
>
> Lo que pretendo hacer es que a traves de otro archivo PHP, se llame a
> este primer archivo y el resultado (la pagina web en codigo HTML) lo
> escriba en un archivo de texto.
>
> Se como escribir en archivos usando PHP pero no se como "redirigir" la
> salida procesada del archivo PHP (osea, el codigo HTML que genera) a
> este archivo.

Se me ocurren dos formas:

1) Haciendo un GET sobre la url del script.

   Si tienes habilitado fopen (en php.ini, no muy recomendable), puedes
   usar algo como

    $handle = fopen("http://servidor/ruta/script.php")

    Y despues leer del $handle y escribir en el archivo. O bien usar la
    biblioteca curl <http://cl2.php.net/curl> ("C-URL", "ver URL").

2) Jugar con los buffers de salida, inhibiendo el responder el texto
   HTML al browser, y recuperandolo en una variable. Para eso puedes
   usar ob_start(), ob_flush(), ob_end(), ob_get_contents() e
   include(). Despues tiras la variable a un archivo.

Releyendo tu pregunta.. me tinca mas la 2 :-)

-- 
Cristian Gutierrez                          /* crgutier@dcc.uchile.cl */
Once upon a time, telling lies for commercial gain was called "fraud"
and punished accordingly. These days it's called "marketing" and
proponents of it are rewarded with high-paying jobs. --  leonbrooks, /.
Technical Details
Message-ID: <87r7e2tfsa.fsf@guti.no-ip.org>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!guti.no-ip.org!news
References: <db43hb$8ac$1@news1.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,56ca42bc43a09e87
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!guti.no-ip.org!news
From: Cristian Gutierrez <crgutier@dcc.uchile.cl>
Newsgroups: chile.comp.programacion
Subject: Re: Ayuda: Vaciar resultado de un PHP a un archivo de texto
Date: Wed, 13 Jul 2005 20:03:33 -0400
Organization: DCC - Universidad de Chile
Lines: 38
Message-ID: <87r7e2tfsa.fsf@guti.no-ip.org>
References: <db43hb$8ac$1@news1.nivel5.cl>
NNTP-Posting-Host: anakena.dcc.uchile.cl
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: helcaraxe.dcc.uchile.cl 1121301075 13226 192.80.24.6 (14 Jul 2005 00:31:15 GMT)
X-Complaints-To: newsmaster@dcc.uchile.cl
NNTP-Posting-Date: Thu, 14 Jul 2005 00:31:15 +0000 (UTC)
Face: iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAADFBMVEUWFhZfX1+ioqL6+vr8
 dj+QAAAAAWJLR0QAiAUdSAAAAg5JREFUeNql0s9r02AYB/B4GIHuoAgVVmG9CVYwf4ILrht40Ynd
 dEXioWUsA3PaQQ8LKHpYLnbTThwiHbWYV9Sj9rL36NUObGkPUrVzuIs/6BvyluZ9ljcxaXI2lzwf
 eJOH9/k+AvhP/7j/Fv65OxMzmynhqO1zH/So+29NLeqvh6YU8WADmemIP4lxL8pxp6p3o2aZegZl
 R3YyaBJNaaGHKkqgxOXQNkKXzLQR+g9C6+b5kfcQevgmpYRuIrRZn5BCryO0US3ogW1BdV0J+3dz
 grpXmQXYfuf5nkLH5ksK/SIrnq/rg26ioTmdygtupwgWHSvoTnvF4CZl17dOYNoWy9yNPOzXfstg
 tYtXuR9o0JwlL+HgeWGBW8ZgGBbFnWUhw33Sbdz6TvHN1ey8a3YGIN+6T2C5PYFdD2sA6d5FAu9v
 LH3WBbAJBgmIDJ3ioooFoCzPNDq5in82TX7egsdXcE+0pZ3sEr+fxW7XoCvS3HRS4f7rrGHojRP0
 6A72TOtuoBrZnVvz5kGIzVejX0jpvi2bF0Q+iz1TWuXFwbOkP7/hrrdaH58u+HakX7wwSsF8/eDT
 wf45417kFwIPd7yIcWDS52UDApevuZ86p0PLK1tuZHpoBN8YLgOM9pswfft/vO9oMf9g6UbMYNij
 /jDYglZwHRCYIIgx56aO4earyPlD89R0Mvo/9kR9HfgIgorhXaQc58oAAAAASUVORK5CYII=
User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)
Cancel-Lock: sha1:mrm47KUFNIQgj5+MoYZIQitFD9I=