Re: [PHP] editing a file

2010-05-24 Thread Rene Veerman
On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
and...@packetstorm.com wrote:
 I have a large C source file that is generated by a separate
 source-generating program. When the generated src file is compiled, it
 produces tons of warnings. I want to edit the generated src file and delete
 the offending lines.

 What is the easiest way using a PHP script to read in a file, search for a
 particular signature, and delete a couple of lines? Seems like this would be
 very easy in PHP.

file_get_contents() to get the file into a $string.

preg_match_all(,,$matches) to get to what you need,

str_replace() to replace $matches with your chosen replacements

and there you are :)

file_put_contents() to save the results..


 Thanks,

 -Andres

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
-
Greetings from Rene7705,

My free open source webcomponents:
  http://code.google.com/u/rene7705/
  http://mediabeez.ws/downloads (and demos)

http://www.facebook.com/rene7705
-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] editing a file

2010-05-24 Thread Andres Gonzalez

thank you Rene, that is the start I needed.

-Andres


Rene Veerman wrote:

On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
and...@packetstorm.com wrote:
  

I have a large C source file that is generated by a separate
source-generating program. When the generated src file is compiled, it
produces tons of warnings. I want to edit the generated src file and delete
the offending lines.

What is the easiest way using a PHP script to read in a file, search for a
particular signature, and delete a couple of lines? Seems like this would be
very easy in PHP.



file_get_contents() to get the file into a $string.

preg_match_all(,,$matches) to get to what you need,

str_replace() to replace $matches with your chosen replacements

and there you are :)

file_put_contents() to save the results..

  

Thanks,

-Andres

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php







  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] editing a file

2010-05-24 Thread Ryan Sun
yea, file_get_contents and file_put_contents are the easiest, but play
with caution when dealing with large files, 'cause it loads the whole
file into memory, fopen() fread() fwrite() can be used for large
files.

On Mon, May 24, 2010 at 5:56 PM, Rene Veerman rene7...@gmail.com wrote:
 On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
 and...@packetstorm.com wrote:
 I have a large C source file that is generated by a separate
 source-generating program. When the generated src file is compiled, it
 produces tons of warnings. I want to edit the generated src file and delete
 the offending lines.

 What is the easiest way using a PHP script to read in a file, search for a
 particular signature, and delete a couple of lines? Seems like this would be
 very easy in PHP.

 file_get_contents() to get the file into a $string.

 preg_match_all(,,$matches) to get to what you need,

 str_replace() to replace $matches with your chosen replacements

 and there you are :)

 file_put_contents() to save the results..


 Thanks,

 -Andres

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





 --
 -
 Greetings from Rene7705,

 My free open source webcomponents:
  http://code.google.com/u/rene7705/
  http://mediabeez.ws/downloads (and demos)

 http://www.facebook.com/rene7705
 -

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] editing a file

2010-05-24 Thread shiplu
You can use shell commands.
Like sed, replace etc ..


Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Editing uploaded file

2002-01-31 Thread Will Hives

It uploads it to: /home/€€/€€/php/
and renames it with the article ID number + the original name eg.
41button.gif

should that work??? It does!!! How would you suggest doing it??



in article [EMAIL PROTECTED], Jason Wong at
[EMAIL PROTECTED] wrote on 1/31/2002 3:00 AM:

 On Thursday 31 January 2002 05:13, will hives wrote:
 I have this version when I add the image on the add article page, and that
 works fine...
 
 
 
 if ($picture != 'none') {
 
 $path = /home/€€/€€/php/;
 $path1 = http://www.€€.net/php/;;
 $b_id = mysql_insert_id();
 $new_pic_name = $b_id$picture_name;
 $imageFile = $path1.$new_pic_name;
 
 copy($picture,$path . $new_pic_name);
 
 
 it's just when it comes to editing the image???
 
 Honestly, I don't see how this code will work. Are you saying that after
 uploading your image, the above code will copy the uploaded image into
 /home/xxx/xxx/php/new_pic_name?
 




Re: [PHP] Editing uploaded file

2002-01-30 Thread will hives

The code attached was just the code which ran the html form there is another
page which contains all the form details, this code just does the editeing
and shows you what it's done.

Cheers
Will


in article [EMAIL PROTECTED], Jason Wong at
[EMAIL PROTECTED] wrote on 30/1/02 3:20 am:

 On Wednesday 30 January 2002 05:32, will hives wrote:
 
 Please do not use HTML mail, thanks!
 
 I have produced an admin area which allows users to add, edit and delete
 stories plus images. Everything has gone great, thanks to all of you who
 answered previous postings.
 
 Just stuck on the very last point...editing...the script below updates the
 name and email fine, but uploading a new image it does not do. Does any one
 have any ideas why the image upload is not working...it echos the new name
 but does not upload the new file
 
 1) You haven't defined a form using form/form so it probably wouldn't
 work in NN.
 
 2) You *need* to define a form specifying the enctype if you're going to be
 uploading stuff:
 
 form name=upload enctype=multipart/form-data method=post
 
 3) You don't have any input boxes, all you have is a submit button. What are
 people supposed to be editing?
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-30 Thread Jason Wong

On Wednesday 30 January 2002 17:10, will hives wrote:
 The code attached was just the code which ran the html form there is
 another page which contains all the form details, this code just does the
 editeing and shows you what it's done.

Could you post the code which does the editing and, in particular, the 
uploading of the image file?



-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
Summit meetings tend to be like panda matings.  The expectations are always 
high, and the results usually disappointing.
-- Robert Orben
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-30 Thread will hives

Jason,

here it all is

thanks for this...
Cheers
Will


HTML EDIT UPLOAD PAGE:
html
head
titlemy contact management system: add a contact/title
/head
body
?

$db_name = ;

$table_name = ;

$connection = @mysql_connect(, , ) or die
(couldn't connect.);

$db = @mysql_select_db($db_name, $connection) or die (couldn't select
database.);

$sql = select name, email, picture_name from $table_name where id
=\$id\;

$result = @mysql_query($sql, $connection) or die (couldn't execute query);



while ($row = mysql_fetch_array($result)) {

$name = $row['name'];
$email = $row['email'];
$picture_name = $row['picture_name'];


}


?


form method=post action=do_editauthor.php
ENCTYPE=multipart/form-data
input type=hidden name=id value=? echo $id; ?
  table cellspace=3 cellpadding=5
tr 
  thName  email information/th
  thnbsp;/th
/tr
tr 
  td valign=top
pstongfont size=-2 face=Verdana, Arial, Helvetica,
sans-serifname:/fontbr
  input type=text name=name value=? echo $name; ? size=35
maxlength=75
/p
pstongfont size=-2 face=Verdana, Arial, Helvetica,
sans-serifemail:/fontbr
  input type=text name=email value=? echo $email; ?
size=35 maxlength=75
  br
/pfont size=-2 face=Verdana, Arial, Helvetica,
sans-serifFile 
to Upload:/fontbr
input type=file name=picture size=30

brbr
?
$pic_name = $id$picture_name;
$path1 = http://www..net/php/;;
$imageFile = $path1.$pic_name;


 
? 
img src=? echo $imageFile; ?
pstong/p
  /td
  td valign=topnbsp;/td
/tr
tr 
  td align=center colspan=2
div align=leftbr
/div
p align=left
  input type=submit name=submit value=add to contact system
/p
div align=left/div
/td
/tr
  /table
/form
/body
/html



THIS IS THE DOING EDIT SCRIPT:

?

$db_name = €€;

$table_name = €€;

$connection = @mysql_connect(€€, €€, €€) or
die (couldn't connect.);

$db = @mysql_select_db($db_name, $connection) or die (couldn't select
database.);

$sql = UPDATE $table_name SET

name = \$name\,
email = \$email\,
picture_name = \$picture_name\
where id = \$id\

;


$result = @mysql_query($sql, $connection) or die (couldn't execute query);


if ($picture) {

$path = /home/€€/€€/php/;
$path1 = http://www.€€.net/php/;;
$b_id = mysql_insert_id();
$new_pic_name = $b_id$picture_name;
$imageFile = $path1.$new_pic_name;

copy($picture,$path . $new_pic_name);


}



? 


html
head
titlemy contact management system: add a contact/title
/head
body

  table cellspace=3 cellpadding=5
tr 
  thName  email information/th
  thnbsp;/th
/tr
tr 
  td valign=top
pstongfont size=-2 face=Verdana, Arial, Helvetica,
sans-serifname:/fontbr
? echo $table_name; ?
  ? echo $name; ?
/p
pstongfont size=-2 face=Verdana, Arial, Helvetica,
sans-serifemail:/fontbr? echo $email; ?
  
  br
/p
font size=-2 face=Verdana, Arial, Helvetica, sans-serifFile
to Upload:/fontbr


?
$new_pic_name = $id$picture_name;
$path1 = http://www.€€.net/php/;;
$imageFile = $path1.$new_pic_name;


if ($new_pic_name == $id) {

print (img 
src=\http://www.€€.co.uk/images/no_image_available.gif\;
width=\162\ height=\113\ border=\0\);
   
} else { 
  
  
print img src=.$imageFile.;


   
 
 }
 ?
 
 
 
 
 br 
  pstong/p
  /td
  td valign=topnbsp;/td
/tr
tr 
  td align=center colspan=2
div align=leftbr
/div
p align=left
  input type=submit name=submit value=add to contact system
/p
div align=left/div
/td
/tr
  /table
/body
/html













in article [EMAIL PROTECTED], Jason Wong at
[EMAIL PROTECTED] wrote on 30/1/02 9:46 am:

 On Wednesday 30 January 2002 17:10, will hives wrote:
 The code attached was just the code which ran the html form there is
 another page which contains all the form details, this code just does the
 editeing and shows you what it's done.
 
 Could you post the code which does the editing and, in particular, the
 uploading of the image file?
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-30 Thread Jason Wong

On Wednesday 30 January 2002 19:27, will hives wrote:

 THIS IS THE DOING EDIT SCRIPT:

[snip]

 if ($picture) {

 $path = /home/€€/€€/php/;
 $path1 = http://www.€€.net/php/;;
 $b_id = mysql_insert_id();
 $new_pic_name = $b_id$picture_name;
 $imageFile = $path1.$new_pic_name;

 copy($picture,$path . $new_pic_name);


 }

IIRC we've been through this before. Please read the manual. You *need* to 
understand how to handle uploaded files (by reading the manual). The above 
code simply would not work.


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
Would you care to drift aimlessly in my direction?
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-30 Thread will hives

I have this version when I add the image on the add article page, and that
works fine...



if ($picture != 'none') {

$path = /home/€€/€€/php/;
$path1 = http://www.€€.net/php/;;
$b_id = mysql_insert_id();
$new_pic_name = $b_id$picture_name;
$imageFile = $path1.$new_pic_name;

copy($picture,$path . $new_pic_name);


it's just when it comes to editing the image???

Sorry about this is must be like banging your head against a brick wall.

Cheers
Will





in article [EMAIL PROTECTED], Jason Wong at
[EMAIL PROTECTED] wrote on 30/1/02 5:56 pm:

 On Wednesday 30 January 2002 19:27, will hives wrote:
 
 THIS IS THE DOING EDIT SCRIPT:
 
 [snip]
 
 if ($picture) {
 
 $path = /home/€€/€€/php/;
 $path1 = http://www.€€.net/php/;;
 $b_id = mysql_insert_id();
 $new_pic_name = $b_id$picture_name;
 $imageFile = $path1.$new_pic_name;
 
 copy($picture,$path . $new_pic_name);
 
 
 }
 
 IIRC we've been through this before. Please read the manual. You *need* to
 understand how to handle uploaded files (by reading the manual). The above
 code simply would not work.
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-30 Thread Jason Wong

On Thursday 31 January 2002 05:13, will hives wrote:
 I have this version when I add the image on the add article page, and that
 works fine...



 if ($picture != 'none') {

 $path = /home/€€/€€/php/;
 $path1 = http://www.€€.net/php/;;
 $b_id = mysql_insert_id();
 $new_pic_name = $b_id$picture_name;
 $imageFile = $path1.$new_pic_name;

 copy($picture,$path . $new_pic_name);


 it's just when it comes to editing the image???

Honestly, I don't see how this code will work. Are you saying that after 
uploading your image, the above code will copy the uploaded image into 
/home/xxx/xxx/php/new_pic_name?


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
Newlan's Truism:
An acceptable level of unemployment means that the 
government economist to whom it is acceptable still has a job.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Editing uploaded file

2002-01-29 Thread Jason Wong

On Wednesday 30 January 2002 05:32, will hives wrote:

Please do not use HTML mail, thanks!

 I have produced an admin area which allows users to add, edit and delete
 stories plus images. Everything has gone great, thanks to all of you who
 answered previous postings.

 Just stuck on the very last point...editing...the script below updates the
 name and email fine, but uploading a new image it does not do. Does any one
 have any ideas why the image upload is not working...it echos the new name
 but does not upload the new file

1) You haven't defined a form using form/form so it probably wouldn't 
work in NN.

2) You *need* to define a form specifying the enctype if you're going to be 
uploading stuff:

form name=upload enctype=multipart/form-data method=post

3) You don't have any input boxes, all you have is a submit button. What are 
people supposed to be editing?


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
A pat on the back is only a few centimeters from a kick in the pants.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]