[PHP-DB] Find and Replace

2003-07-21 Thread Chris Payne
Hi there everyone,

I have a DB system which i've just rewritten for a travel website.  Previously it used 
BR's for linebreaks but i've made it much more efficient.  My problem it, there are 
10+ travel guides which us BR's and I want to remove them on over 100 pages (In a 
MySQL DB).

Using PHP, how can I write a simple script to go through all the entries for a column 
(Called articles) and remove all instances of br or BR ???  It would take far too 
long to do it page by page :-(

Thanks for all your help everyone.

Regards

Chris Payne

Re: [PHP-DB] Find and Replace

2003-07-21 Thread John W. Holmes
Chris Payne wrote:
I have a DB system which i've just rewritten for a travel website.  Previously it used BR's for linebreaks but i've made it much more efficient.  My problem it, there are 10+ travel guides which us BR's and I want to remove them on over 100 pages (In a MySQL DB).

Using PHP, how can I write a simple script to go through all the entries for a column (Called articles) and remove all instances of br or BR ???  It would take far too long to do it page by page :-(
I know this is a PHP list, but why use PHP?

UPDATE table SET column = REPLACE(column,'BR','');
UPDATE table SET column = REPLACE(column,'br','');
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals  www.phparch.com





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


Re: [PHP-DB] Find and Replace

2003-07-21 Thread Chris Payne
Hi there,

Ahhh thanks, that was a quick way to do it, I took the long way around LOL
:-)

I grabbed the data, did $article = str_replace(br, , $article); and
then looped through all of the entries to change it, it seems to have worked
though :-)

Chris

 Chris Payne wrote:
  I have a DB system which i've just rewritten for a travel website.
Previously it used BR's for linebreaks but i've made it much more
efficient.  My problem it, there are 10+ travel guides which us BR's and I
want to remove them on over 100 pages (In a MySQL DB).
 
  Using PHP, how can I write a simple script to go through all the entries
for a column (Called articles) and remove all instances of br or BR ???
It would take far too long to do it page by page :-(

 I know this is a PHP list, but why use PHP?

 UPDATE table SET column = REPLACE(column,'BR','');
 UPDATE table SET column = REPLACE(column,'br','');

 -- 
 ---John Holmes...

 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

 PHP|Architect: A magazine for PHP Professionals  www.phparch.com





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




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



[PHP-DB] Find and replace in a string

2003-01-26 Thread Nikos Gatsis
Hi list!
I have a sting that contains some occurances of {...} sub-strings, where  is 
some text.
Which is the way to find and replace the {...} with an other of my own.
This sub-strings start with { and end with }.
Thanks




RE: [PHP-DB] Find and replace in a string

2003-01-26 Thread John W. Holmes
 I have a sting that contains some occurances of {...} sub-strings,
where
  is some text.
 Which is the way to find and replace the {...} with an other of my
own.
 This sub-strings start with { and end with }.

If you know what the text is between { and }, then use

$new_str = str_replace({test},replacement,$old_str);

If you don't, then you can use a regular expression to match and replace
it.

---John Holmes...



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




Re: [PHP-DB] Find and replace in a string

2003-01-26 Thread Paul Chvostek
On Mon, Jan 27, 2003 at 12:57:10AM +0200, Nikos Gatsis wrote:

 Hi list!
 I have a sting that contains some occurances of {...} sub-strings, where  is 
some text.
 Which is the way to find and replace the {...} with an other of my own.
 This sub-strings start with { and end with }.

You could try something with a regular expression like:

$new = ereg('[^{]*{([^}]*)}.*', '\\1', $oldstring);

which will match only the first word inside curly braces, or if
$oldstring contains multiple strings in curly braces, maybe:

$newarray = split('}?[^{]*{', $oldstring . '{');

and then parse the array, and you'll probably want to toss [0], as it
will contain the data before the first left-curly-brace.  This method
needs a trailing left-curly-brace appended to $oldstring because the
regexp relies on it to mark the field.  You could alternately turn this
around as:

$newarray = split('}[^{]*{?', '}' . $oldstring);

which is probably the cleanest way to do this, given the extent to which
you've described the data so far.  Note that split() will work just fine
on multi-line arrays, including fields split over multiple lines.  If
you want to process your data line-by-line, you'd need to wrap it.

The better you can predict the input data, the cleaner the code you can
use to parse it.

Learn the regexps.

-- 
  Paul Chvostek [EMAIL PROTECTED]
  Operations / Abuse / Whatever
  it.canada, hosting and development   http://www.it.ca/


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




[PHP-DB] Find - n - replace

2001-05-22 Thread John Starkey

Hello all.

I'm trying to set up a quick find and replace script. It's finding, and
it's pasting what I want, but on the following line, I can't get it to
replace. Can anyone help?

#!/usr/local/bin/php -q

?php

$fp = fopen( ./somefile.html,r+);
while ( !feof( $fp ) ) {
$line = fgets( $fp, 4096 );
if ( eregi( td, $line ) ) {
if ( eregi( 4[0-9]{2}, $line ) ) {
$liner = eregi_replace( 4[0-9]{2}, 470, $line );
fputs( $fp, $liner, strlen( $liner ) );
}
}
}

fclose( $fp );

?

Can anyone tell me how I can back the fput up one line so it overwrites
the result of the search?

Thanks,

John


-- 
PHP Database 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-DB] Find - n - replace

2001-05-22 Thread matthew knight

try looking at the fseek function, i think that does what you want:
http://uk.php.net/manual/en/function.fseek.php


John Starkey [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hello all.

 I'm trying to set up a quick find and replace script. It's finding, and
 it's pasting what I want, but on the following line, I can't get it to
 replace. Can anyone help?

 #!/usr/local/bin/php -q

 ?php

 $fp = fopen( ./somefile.html,r+);
 while ( !feof( $fp ) ) {
 $line = fgets( $fp, 4096 );
 if ( eregi( td, $line ) ) {
 if ( eregi( 4[0-9]{2}, $line ) ) {
 $liner = eregi_replace( 4[0-9]{2}, 470, $line );
 fputs( $fp, $liner, strlen( $liner ) );
 }
 }
 }

 fclose( $fp );

 ?

 Can anyone tell me how I can back the fput up one line so it overwrites
 the result of the search?

 Thanks,

 John


 --
 PHP Database 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]




-- 
PHP Database 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]