editing some parts of a text file?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

mudkicker
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 09, 2003 7:31 am

editing some parts of a text file?

Postby mudkicker » Fri May 09, 2003 7:42 am

Hi,
I have a problem by editing a file. I need to change some parts of this file with PHP. Here is the file and then listen to my problem :
****************************************
itemcount=8&symbol1=<a href="http://www.link1.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header1</b>&price1=<a href="http://www.sublink1.com">1 Milyonuncu Audi quattro® yollarda...&symbol2=<a href="http://www.link2.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header2</b></font>&price2=<a href="http://www.sublink2.com">Audi Satýþ Danýþmanlarý Almanya’yý fethetti.&symbol3=<a href="http://www.link3.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header3</b>&price3=<a href="http://www.sublink3.com">Audi 2000’i satýþ ve karda rekorla kapadý!&symbol4=<a href="http://www.link4.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header4</b>&price4=<a href="http://www.sublink4.com">Yüzyýlýn ilk bayi toplantýsý&symbol5=<a href="http://www.Link5.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header5</b>&price5=<a href="http://www.sublink5.com">2000 yýlý Audi’ye uðurlu geldi!&symbol6=<a href="http://www.link6.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header6</b>&price6=<a href="http://www.sublink6.com">Yeni A4 Yýlýn Otomobili &symbol7=<a href="http://www.link7.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header7</b>&price7=<a href="http://www.sublink7.com">Audi Yetkili Satýcýlarý buz üstünde &symbol8=<a href="http://www.link8.com"><FONT FACE="Arial Tur" SIZE="11" COLOR="#FF0000"><b>header8</b>&price8=<a href="http://www.sublink8.com">EuroNCAP’den Yeni Audi A4’e güvenlik için dört yýldýz&eof=1
*****************************

The places I want to change is the text parts after the variables like &price1 &price2 ... AND &symbol1 &symbol2 ...

How can I do this? Help me please. Thank You! :roll:

sleepingdanny
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Mar 17, 2003 6:38 am

Postby sleepingdanny » Sun May 11, 2003 4:57 am

Do you mean that you want a code that will allow you to change the file in a textarea :?: If so... I Can help you.

mudkicker
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 09, 2003 7:31 am

Postby mudkicker » Sun May 11, 2003 11:32 am

no.
i wrote the code you said.
but that's not the way i want.
:wink:

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sun May 11, 2003 10:23 pm

Code: Select all

<?
$fs=fopen("yourfile.txt", "r");
$content=fread($fs, filesize ("yourfile.txt"));
fclose($fs);

$content=eregi_replace("&price1", "&price2", $content);

$fs=fopen("yourfile.txt", "w");
fwrite($fs, $content);
fclose($fs);
?>

this part is regular expresion for chaging text
$content=eregi_replace("&price1", "&price2", $content);

mudkicker
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 09, 2003 7:31 am

Postby mudkicker » Mon May 12, 2003 12:21 am

pejone, this script changes the variables not the values.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Mon May 12, 2003 12:27 am

pejone, this script changes the variables not the values.


this is just sample , you can edit ereg_replace for you patern...


Return to “PHP coding => General”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests