str_replace() external file

This is a discussion on str_replace() external file within the PHP Language forums, part of the PHP Programming Forums category; I have this page (print.php). In that file, I want to to include a text file from "songs/...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-26-2006
The Numerator
 
Posts: n/a
Default str_replace() external file

I have this page (print.php). In that file, I want to to include a text
file from "songs/breathe.txt", and replace all instances of "<b" with
"<span" and "</b>" with "</span>". I know how I should use str_replace
and I tried to do this:

<?php

$replace_a=str_replace("<span","<b",include("text/breathe.txt"));
$replace_b=str_replace("</span>",</b>",$replace_a);

?>

but it doesn't work.

Reply With Quote
  #2 (permalink)  
Old 07-26-2006
PTM
 
Posts: n/a
Default Re: str_replace() external file

"The Numerator" <alvin4jesus@gmail.com> wrote in message
news:1153951139.069847.269920@m73g2000cwd.googlegr oups.com...
>I have this page (print.php). In that file, I want to to include a text
> file from "songs/breathe.txt", and replace all instances of "<b" with
> "<span" and "</b>" with "</span>". I know how I should use str_replace
> and I tried to do this:
>
> <?php
>
> $replace_a=str_replace("<span","<b",include("text/breathe.txt"));
> $replace_b=str_replace("</span>",</b>",$replace_a);
>
> ?>
>
> but it doesn't work.
>


I've never tried that before, but I'm sure it's never going to do it.

What you should do is open the file and read it in

$file='[PATH TO FILE]';
$filethis=fopen($file,'rb') or die("Can't open TXT file '[FILENAME]'");

Then read each line of the file, doing your replace as you go.


Phil


Reply With Quote
  #3 (permalink)  
Old 07-27-2006
Miguel Cruz
 
Posts: n/a
Default Re: str_replace() external file

"The Numerator" <alvin4jesus@gmail.com> wrote:
> I have this page (print.php). In that file, I want to to include a text
> file from "songs/breathe.txt", and replace all instances of "<b" with
> "<span" and "</b>" with "</span>". I know how I should use str_replace
> and I tried to do this:
>
> <?php
>
> $replace_a=str_replace("<span","<b",include("text/breathe.txt"));
> $replace_b=str_replace("</span>",</b>",$replace_a);
>
> ?>
>
> but it doesn't work.


$replace_a
= str_replace('<span', '<b', file_get_contents('text/breathe.txt'));

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Reply With Quote
  #4 (permalink)  
Old 07-28-2006
The Numerator
 
Posts: n/a
Default Re: str_replace() external file


Miguel Cruz wrote:
> "The Numerator" <alvin4jesus@gmail.com> wrote:
> > I have this page (print.php). In that file, I want to to include a text
> > file from "songs/breathe.txt", and replace all instances of "<b" with
> > "<span" and "</b>" with "</span>". I know how I should use str_replace
> > and I tried to do this:
> >
> > <?php
> >
> > $replace_a=str_replace("<span","<b",include("text/breathe.txt"));
> > $replace_b=str_replace("</span>",</b>",$replace_a);
> >
> > ?>
> >
> > but it doesn't work.

>
> $replace_a
> = str_replace('<span', '<b', file_get_contents('text/breathe.txt'));
>
> miguel
> --
> Photos from 40 countries on 5 continents: http://travel.u.nu
> Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
> Airports of the world: http://airport.u.nu



sorry, this didn't work

Reply With Quote
  #5 (permalink)  
Old 07-29-2006
The Numerator
 
Posts: n/a
Default Re: str_replace() external file


The Numerator wrote:
> Miguel Cruz wrote:
> > "The Numerator" <alvin4jesus@gmail.com> wrote:
> > > I have this page (print.php). In that file, I want to to include a text
> > > file from "songs/breathe.txt", and replace all instances of "<b" with
> > > "<span" and "</b>" with "</span>". I know how I should use str_replace
> > > and I tried to do this:
> > >
> > > <?php
> > >
> > > $replace_a=str_replace("<span","<b",include("text/breathe.txt"));
> > > $replace_b=str_replace("</span>",</b>",$replace_a);
> > >
> > > ?>
> > >
> > > but it doesn't work.

> >
> > $replace_a
> > = str_replace('<span', '<b', file_get_contents('text/breathe.txt'));
> >
> > miguel
> > --
> > Photos from 40 countries on 5 continents: http://travel.u.nu
> > Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
> > Airports of the world: http://airport.u.nu

>
>
> sorry, this didn't work


actually, i was wrong...i got it to work...

<?php
$content=file_get_contents($txt);
$replace=str_replace("<b","<span",$content);
echo(str_replace("</b>","</span>",$replace));
?>

thx

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:28 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0