473,769 Members | 6,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Jul 26 '06 #1
4 4577
PTM
"The Numerator" <al*********@gm ail.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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
Jul 26 '06 #2
"The Numerator" <al*********@gm ail.comwrote:
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('<s pan', '<b', file_get_conten ts('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
Jul 27 '06 #3

Miguel Cruz wrote:
"The Numerator" <al*********@gm ail.comwrote:
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('<s pan', '<b', file_get_conten ts('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

Jul 28 '06 #4

The Numerator wrote:
Miguel Cruz wrote:
"The Numerator" <al*********@gm ail.comwrote:
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('<s pan', '<b', file_get_conten ts('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_g et_contents($tx t);
$replace=str_re place("<b","<sp an",$content) ;
echo(str_replac e("</b>","</span>",$replace ));
?>

thx

Jul 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4608
by: Jon | last post by:
Why does the following not replace the ":)"? str_replace(":)", "&nbsp;<img src=http://www.com.com/forum/emoticons/smiley.gif>&nbsp;", $_POST); But, the following does replace the ":("? str_replace(":(", "&nbsp;<img src=http://www.com.com/forum/emoticons/crying.gif>&nbsp;", $_POST);
8
2156
by: chris | last post by:
ok - please forgive me if i dont make sence - ill try to explain what i want to do i have an file that i want to change a few srings in it (its a .htm file) i use the str_replace funtion to replace the nessasary strings - i then want to include the result in the php file that is doing the changes. this is what i have got
1
1678
by: marcomputers | last post by:
Hi, I'm trying to automatically update an existing rss podcast file using php and the str_replace function. Every time I add a media file, it should read the .rss file into a string, take the closing </channel> and </rss> tags out of it, and add the new rss file info to the end of the existing string, writing it back to the rss file. However, str_replace will not replace the </channel> and </rss> tags with ' '. I'm new to php, any help...
9
43160
by: Wayne | last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test $p = str_replace ("%0D%0A", "<br>", $a); That is the above code that I am using, however, it is not picking up the CR/LF from the textarea. I have also attempted singular variations of the CR/LF combination and even reversed the sequence without success. Is it possible that it may be encoded differently and if so what is it? Thanks
2
1460
by: alexandre.suc | last post by:
Bonjour Je désire utiliser un str_replace sur une variable qui contient le résultat d'une commande system(). Bizarrement le STR_REPLACE semble sans effet exemple de mon code $entree = system('ls') ;
2
5332
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
5
1694
by: jmark | last post by:
I saw this example in php.net // Outputs: apearpearle pear $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text); echo $output; and I am bit puzzled why the output is the way it is instead of
3
3446
by: Confused but working on it | last post by:
So I've been trying to get a bit of code to: Read all of the files in a dir called thumbs, but not the . and .., use the filename in a link to get the same filename in an images dir. Now I'm trying to use a foreach and glob as suggested, and get rid of the part of the string that has the dir info. SO the below produces all my thumbs nicely and all are links. <?php foreach (glob("thumbs/*.jpg") as $file) {
4
2884
by: jfcby | last post by:
Hello, My data.txt file is formated like this: qqqq||eeee rrrr||tttt yyyy||uuuu iiii||oooo aaaa||bbbb
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.