[PHP] help with preg_replace pattern

2010-01-26 Thread Rob Gould
It appears that IE renders it's display: none in all caps while Firefox and 
other browsers pass it back in lowercase.  This throws off my php line of code 
the is supposed to nuke blank bullets from a string of text:
$bl = 
LI style=DISPLAY: none id=bullet_ug2_col5_8/LI 
LI style=DISPLAY: none id=bullet_ug2_col4_8/LI 
LI style=DISPLAY: none id=bullet_ug2_col3_8/LI 
LI style=DISPLAY: none id=bullet_ug2_col2_8/LI 
LI style=DISPLAY: none id=bullet_ug2_8/LI 
LI style=DISPLAY: none id=bullet_ug1_col4_8/LI 
LI style=DISPLAY: list-item id=bullet_ug1_col3_8Reserved Frontstretch Tower 
Ticket to the NextEra Energy Resources 250 on Friday Night /LI 
LI style=DISPLAY: list-item id=bullet_ug1_col2_8Reserved Frontstretch Tower 
Ticket to the Camping World 300 on Saturday /LI 
LI style=DISPLAY: list-item id=bullet_2_8Reserved Frontstretch Tower Ticket 
to the Daytona 500 on Sunday /LI 
LI style=DISPLAY: none id=bullet_addon_col2_8/LI 
LI style=DISPLAY: none id=bullet_addon3_8/LI 
LI style=DISPLAY: none id=bullet_option2_col4_8/LI 
LI style=DISPLAY: none id=bullet_option2_col3_8/LI 
LI style=DISPLAY: none id=bullet_option2_col2_8/LI 
LI style=DISPLAY: none id=bullet_option2_col1_8/LI 
LI style=DISPLAY: none id=bullet_option3_col4_8/LI 
LI style=DISPLAY: none id=bullet_option3_col3_8/LI 
LI style=DISPLAY: none id=bullet_option3_col2_8/LI 
LI style=DISPLAY: none id=bullet_option3_col1_8/LI 
LI style=DISPLAY: none id=bullet_option4_col4_8/LI 
LI style=DISPLAY: none id=bullet_option4_col3_8/LI

I want to keep the DISPLAY: list-item lines, and nuke all the others.
The below above are sent to PHP in a variable called $bl.  I then try to nuke 
the DISPLAY: none lines with something like:

$pattern = '/li[^]*style=display: none[^]*/';
$bl = preg_replace($pattern,'',$bl);

$pattern = '/li[^]*style=DISPLAY: none[^]*/';
$bl = preg_replace($pattern,'',$bl);

But it appears that the case-sensitivity fix is not just a matter of making the 
letter capitals.  I'm sure someone who knows more than I about preg_replace 
will see the 
immediate error of my ways.  Any advice is greatly appreciated.







Re: [PHP] help with preg_replace pattern

2010-01-26 Thread Adam Richardson
On Tue, Jan 26, 2010 at 10:37 PM, Rob Gould gould...@mac.com wrote:

 It appears that IE renders it's display: none in all caps while Firefox and
 other browsers pass it back in lowercase.  This throws off my php line of
 code the is supposed to nuke blank bullets from a string of text:
 $bl =
 LI style=DISPLAY: none id=bullet_ug2_col5_8/LI
 LI style=DISPLAY: none id=bullet_ug2_col4_8/LI
 LI style=DISPLAY: none id=bullet_ug2_col3_8/LI
 LI style=DISPLAY: none id=bullet_ug2_col2_8/LI
 LI style=DISPLAY: none id=bullet_ug2_8/LI
 LI style=DISPLAY: none id=bullet_ug1_col4_8/LI
 LI style=DISPLAY: list-item id=bullet_ug1_col3_8Reserved Frontstretch
 Tower Ticket to the NextEra Energy Resources 250 on Friday Night /LI
 LI style=DISPLAY: list-item id=bullet_ug1_col2_8Reserved Frontstretch
 Tower Ticket to the Camping World 300 on Saturday /LI
 LI style=DISPLAY: list-item id=bullet_2_8Reserved Frontstretch Tower
 Ticket to the Daytona 500 on Sunday /LI
 LI style=DISPLAY: none id=bullet_addon_col2_8/LI
 LI style=DISPLAY: none id=bullet_addon3_8/LI
 LI style=DISPLAY: none id=bullet_option2_col4_8/LI
 LI style=DISPLAY: none id=bullet_option2_col3_8/LI
 LI style=DISPLAY: none id=bullet_option2_col2_8/LI
 LI style=DISPLAY: none id=bullet_option2_col1_8/LI
 LI style=DISPLAY: none id=bullet_option3_col4_8/LI
 LI style=DISPLAY: none id=bullet_option3_col3_8/LI
 LI style=DISPLAY: none id=bullet_option3_col2_8/LI
 LI style=DISPLAY: none id=bullet_option3_col1_8/LI
 LI style=DISPLAY: none id=bullet_option4_col4_8/LI
 LI style=DISPLAY: none id=bullet_option4_col3_8/LI

 I want to keep the DISPLAY: list-item lines, and nuke all the others.
 The below above are sent to PHP in a variable called $bl.  I then try to
 nuke the DISPLAY: none lines with something like:

 $pattern = '/li[^]*style=display: none[^]*/';
 $bl = preg_replace($pattern,'',$bl);

 $pattern = '/li[^]*style=DISPLAY: none[^]*/';
 $bl = preg_replace($pattern,'',$bl);

 But it appears that the case-sensitivity fix is not just a matter of making
 the letter capitals.  I'm sure someone who knows more than I about
 preg_replace will see the
 immediate error of my ways.  Any advice is greatly appreciated.






Your regex is looking for case-sensitive matches, which given the example
below, would preclude all of your list items (they all start with LI, not
li.)

Try using a case insensitive regex (e.g., $bl = preg_replace($pattern
= /li[^]*style=DISPLAY: none[^]*/i','',$bl);

(Note the i after the search pattern above.)

Adam


-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com


[PHP] Help with preg_replace

2007-11-07 Thread Richard Luckhurst
Hi 

I am in the process of porting a Perl application to PHP and I have hit a snag
with trying to substitute test within a file. I have looked at the PHP manual
and believe I should be using preg_replace but I have tried the examples and am
not getting the result I would expect. I would appreciate any help in getting
this to work.

In Perl I have the following

$html = `cat htmlfile`;
$html  =~ s/%ResID/$bookid/g;

which replaces each instance of %ResID with the contents of the variable $bookid

In PHP I have tried

$html = `cat htmlfile`;
$html = preg_replace('%ResID',$bookid,$html);

When I run this I find $html is empty rather than containing the file with the
%ResID replaced with the contents of $bookid.

I would appreciate any help with my understanding of preg_replace.



Regards,
Richard Luckhurst  
Product Development
Exodus Systems - Sydney, Australia.
[EMAIL PROTECTED]
Tel: (+612) 4751-9633
Fax: (+612) 4751-9644
Web: www.resmaster.com 
=
Exodus Systems - Smarter Systems, Better Business
=

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



Re: [PHP] help with preg_replace only part of the string

2005-12-06 Thread David Grant
Replace the middle (.*) with ([^]*).  This tells the regex engine to
ignore new opening tags.

Cheers,

David

Georgi Ivanov wrote:
 Hi,
 I want to replace the content of html links : a href=foo 
 name=blaREPLACETHIS/a.
 
 $html=preg_replace(/(a.*name=.*)(.*)\/a/isU,$link,$html,1);
 This generally works but removes a,/a tags too.
 How to make it work without removing anything else than (.*) in the middle of 
 a.*/a
 
 Thanks in advance.
 


-- 
David Grant
http://www.grant.org.uk/

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



Re: [PHP] help with preg_replace only part of the string

2005-12-06 Thread Richard Heyes

Georgi Ivanov wrote:

Hi,
I want to replace the content of html links : a href=foo 
name=blaREPLACETHIS/a.


$html=preg_replace(/(a.*name=.*)(.*)\/a/isU,$link,$html,1);
This generally works but removes a,/a tags too.
How to make it work without removing anything else than (.*) in the middle of 
a.*/a


$html = preg_replace(/(a.*name=.*)(.*)\/a/isU, '\1' . $link . 
'/a', $html, 1);


--
Richard Heyes
http://www.phpguru.org

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



Re: [PHP] help with preg_replace only part of the string

2005-12-06 Thread Miles Thompson

At 07:06 AM 12/6/2005, Richard Heyes wrote:

Georgi Ivanov wrote:

Hi,
I want to replace the content of html links : a href=foo 
name=blaREPLACETHIS/a.

$html=preg_replace(/(a.*name=.*)(.*)\/a/isU,$link,$html,1);
This generally works but removes a,/a tags too.
How to make it work without removing anything else than (.*) in the 
middle of a.*/a


$html = preg_replace(/(a.*name=.*)(.*)\/a/isU, '\1' . $link . 
'/a', $html, 1);


--
Richard Heyes
http://www.phpguru.org


If you know what you are replacing, i.e. REPLACETHIS is a placeholder, 
str_replace() or substr_replace() are much simpler.


Miles Thompson

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



[PHP] Help with preg_replace

2005-07-04 Thread Marcos Mendonça
Hi list

I need help to solve a preg_replace() problem.

I have a snippet of html code that contains some links.

I have an array thats contains all links inside that snippet of html code.

What i need to do is replace all the links in the code by another on.

So this is what i´m trying to do:

//links that should be replaced
$url = array(
array(id = 0, url = 
http://www.silika.com.br/conarh/mala3;),
array(id = 1, url = http://www.conarh.com.br;),
array(id = 2, url =
http://www.conarh.com.br/main_frameset.php?secao=congressoidioma=portpagina=http://www.conarh.com.br/programacao/pub/index.php?tipo_barra=laranja;),
array(id = 3, url =
http://www.conarh.com.br/main_frameset.php?secao=congressoidioma=portpagina=http://www.conarh.com.br/mensagem/pub/mensagem.php?id_mensagem=insc_temptipo_barra=laranja;),
array(id = 4, url =
http://www.silika.com.br/conarh/patrocinio/patrocinio.htm;));

$escape_chars = array(?, /);
$escaped_chars = array(\?, \/);

$matches = array();

foreach ($url as $link) {
$pattern = / . str_replace($escape_chars, $escaped_chars, 
$link[url]) ./;
$newurl = URL_LINKS.linkId=.$link[id].rId=1;
$body_html = preg_replace($pattern, $newurl, $body_html, 1);
}

This works fine for links with id 0, 1 and 4. But i haven´t been able
to figure out how to match and replace links with id 2 and 3.

How do I get my regex to match and replace those links as well? Any
help appreciated.

Thanks.

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



Re: [PHP] Help with preg_replace

2005-07-04 Thread Jason Wong
On Tuesday 05 July 2005 02:21, Marcos Mendonça wrote:

 This works fine for links with id 0, 1 and 4. But i haven´t been able
 to figure out how to match and replace links with id 2 and 3.

Works for me. Check whether $body_html really does contain what you're 
looking for in id 2  id 3.

You may also want to consider using preg_quote() instead of str_replace().

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
New Year Resolution: Ignore top posted posts

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



[PHP] Help with preg_replace

2004-01-19 Thread John Clegg
Hi

I am having some problems with preg_replace and I wondering if someone 
could suggest a fix or explain why it is not working.



Here is the Code:
*
?php
$code = blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah;
$url = 'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]';
echo BEFORE : $codebrbr;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $codebr;
?
**
Here is the results of the script:

**
BEFORE : blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

AFTER: blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

**

It should give the following result:

**

AFTER: blah Foo blah

**

Thanks for your help

Regards

John Clegg

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


Re: [PHP] Help with preg_replace

2004-01-19 Thread joel boonstra
On Mon, Jan 19, 2004 at 06:50:37PM +0200, John Clegg wrote:
 Hi
 
 I am having some problems with preg_replace and I wondering if someone 
 could suggest a fix or explain why it is not working.
 
 
 
 Here is the Code:
 *
 ?php
 $code = blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah;
 $url = 'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]';
 echo BEFORE : $codebrbr;
 $replace  = Foo;
 $code = preg_replace($url,$replace,$code,1);
 echo AFTER: $codebr;
 ?
 **
 
 Here is the results of the script:
 
 **
 BEFORE : blah 
 http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah
 
 AFTER: blah 
 http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah
 
 **
 
 It should give the following result:
 
 **
 
 AFTER: blah Foo blah
 
 **

preg_replace expects the first argument to be a pattern, which should be
enclosed in forward slashes (//).  So your $url variable should be
surrounded with slashes.  You have single quotes in your $url variable,
but I don't think that PHP behaves like perl in letting you use
whichever delimiter you choose.  Try replacing the single quotes with
forward slashes.

Additionally, if you're only doing a simple string substitution, you
should use str_replace instead:

  http://php.net/str_replace

You won't need the / delimiters, and it will be faster than using
preg_replace.

joel

-- 
[ joel boonstra | gospelcom.net ]

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



Re: [PHP] Help with preg_replace

2004-01-19 Thread John Nichel
John Clegg wrote:

Hi

I am having some problems with preg_replace and I wondering if someone 
could suggest a fix or explain why it is not working.



Here is the Code:
*
?php
$code = blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah;
$url = 'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]';
echo BEFORE : $codebrbr;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $codebr;
?
**
Here is the results of the script:

**
BEFORE : blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

AFTER: blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

**

It should give the following result:

**

AFTER: blah Foo blah

**
$url = 
/http:\/\/www.foo.com\/maxbid\/Unsubscribe.php?EmailAddress=\[MAIL\]/;

Will replace http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] 
only.  If you're looking to replace any URL, you need a regular 
expression.  The first argument to preg_replace is the pattern you're 
looking for, so you need to enclose it in slashes ( /pattern/ ), and 
escape out any special characters.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Help with preg_replace

2004-01-19 Thread John Clegg
Hi Joel,

Thanks for the reply.

I have tried using  / to delimit the string  and I get the following error

String

$url = /http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]/;;

Gives the error:
*Warning*: Unknown modifier '/' in* /test.php* on line *8*
I found out that I could use  ' to delimit from Example 5 in the php 
manual page for preg_replace.

Also I need to  replace only one occurance of the string at a time, so I 
can't use str_replace :-( .

Any other suggestions??

Cheers

John



joel boonstra wrote:

On Mon, Jan 19, 2004 at 06:50:37PM +0200, John Clegg wrote:
 

Hi

I am having some problems with preg_replace and I wondering if someone 
could suggest a fix or explain why it is not working.



Here is the Code:
*
?php
$code = blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] blah;
$url = 'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]';
echo BEFORE : $codebrbr;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $codebr;
?
**
Here is the results of the script:

**
BEFORE : blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

AFTER: blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

**

It should give the following result:

**

AFTER: blah Foo blah

**
   

preg_replace expects the first argument to be a pattern, which should be
enclosed in forward slashes (//).  So your $url variable should be
surrounded with slashes.  You have single quotes in your $url variable,
but I don't think that PHP behaves like perl in letting you use
whichever delimiter you choose.  Try replacing the single quotes with
forward slashes.
Additionally, if you're only doing a simple string substitution, you
should use str_replace instead:
 http://php.net/str_replace

You won't need the / delimiters, and it will be faster than using
preg_replace.
joel

 

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


Re: [PHP] Help with preg_replace

2004-01-19 Thread John Clegg
Hi

I have just realised that I have to delimit the following characters so 
I can use preg_replace:
/
?
[
]

Is there any php command to delimit all of these characters as I am 
getting the string I am trying to replace from the database.

eg.

\?

Any ideas

John

John Clegg wrote:

Hi Joel,

Thanks for the reply.

I have tried using  / to delimit the string  and I get the following 
error

String

$url = /http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]/;;

Gives the error:
*Warning*: Unknown modifier '/' in* /test.php* on line *8*
I found out that I could use  ' to delimit from Example 5 in the php 
manual page for preg_replace.

Also I need to  replace only one occurance of the string at a time, so 
I can't use str_replace :-( .

Any other suggestions??

Cheers

John



joel boonstra wrote:

On Mon, Jan 19, 2004 at 06:50:37PM +0200, John Clegg wrote:
 

Hi

I am having some problems with preg_replace and I wondering if 
someone could suggest a fix or explain why it is not working.



Here is the Code:
*
?php
$code = blah http://www.foo.com/Unsubscribe.php?EmailAddress=[MAIL] 
blah;
$url = 
'http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]';
echo BEFORE : $codebrbr;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $codebr;
?
**

Here is the results of the script:

**
BEFORE : blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] 
blah

AFTER: blah 
http://www.qxlmaxbid.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] 
blah

**

It should give the following result:

**

AFTER: blah Foo blah

**
  


preg_replace expects the first argument to be a pattern, which should be
enclosed in forward slashes (//).  So your $url variable should be
surrounded with slashes.  You have single quotes in your $url variable,
but I don't think that PHP behaves like perl in letting you use
whichever delimiter you choose.  Try replacing the single quotes with
forward slashes.
Additionally, if you're only doing a simple string substitution, you
should use str_replace instead:
 http://php.net/str_replace

You won't need the / delimiters, and it will be faster than using
preg_replace.
joel

 


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


Re: [PHP] Help with preg_replace

2004-01-19 Thread joel boonstra
On Mon, Jan 19, 2004 at 07:15:53PM +0200, John Clegg wrote:
 Hi Joel,
 
 Thanks for the reply.
 
 I have tried using  / to delimit the string  and I get the following error
 
 String
 
 $url = /http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL]/;;
 
 Gives the error:
 *Warning*: Unknown modifier '/' in* /test.php* on line *8*
 
 I found out that I could use  ' to delimit from Example 5 in the php 
 manual page for preg_replace.

Whoops, you're totally right.  The single quote should work fine.  I
shouldn't underestimate PHP ;)

 Also I need to  replace only one occurance of the string at a time, so I 
 can't use str_replace :-( .
 
 Any other suggestions??

The problem is that there are still special chars that need escaping.
Specifically, the question mark (?) and the square braces ([]).

Here is some modified code (apologies for poor word-wrapping):

?php
$code = blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah ;
$url = 'http://www.foo.com/maxbid/Unsubscribe.php\?EmailAddress=\[MAIL\]';
echo BEFORE : $code\n\n;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $code\n;
?

When I run this, the output is:

BEFORE : blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

AFTER: blah Foo blah

Next time, I'll test out my answers before I give 'em.

HTH!

-- 
[ joel boonstra | gospelcom.net ]

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



Re: [PHP] Help with preg_replace

2004-01-19 Thread John Nichel
John Clegg wrote:

Hi

I have just realised that I have to delimit the following characters so 
I can use preg_replace:
/
?
[
]

Is there any php command to delimit all of these characters as I am 
getting the string I am trying to replace from the database.

eg.

\?

Any ideas

John
Maybe addslashes(), but I don't know if that will escape all the 
characters you need.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Help with preg_replace

2004-01-19 Thread John Nichel
John Nichel wrote:
John Clegg wrote:

Hi

I have just realised that I have to delimit the following characters 
so I can use preg_replace:
/
?
[
]

Is there any php command to delimit all of these characters as I am 
getting the string I am trying to replace from the database.

eg.

\?

Any ideas

John


Maybe addslashes(), but I don't know if that will escape all the 
characters you need.

Check that...addslashes() won't escape [].

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Help with preg_replace

2004-01-19 Thread Jason Wong
On Tuesday 20 January 2004 01:31, John Clegg wrote:

 Is there any php command to delimit all of these characters as I am
 getting the string I am trying to replace from the database.

preg_quote()

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
WYSIWYG:
What You See Is What You Get.
*/

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



Re: [PHP] Help with preg_replace

2004-01-19 Thread John W. Holmes
joel boonstra wrote:

The problem is that there are still special chars that need escaping.
Specifically, the question mark (?) and the square braces ([]).
Here is some modified code (apologies for poor word-wrapping):

?php
$code = blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah ;
$url = 'http://www.foo.com/maxbid/Unsubscribe.php\?EmailAddress=\[MAIL\]';
echo BEFORE : $code\n\n;
$replace  = Foo;
$code = preg_replace($url,$replace,$code,1);
echo AFTER: $code\n;
?
When I run this, the output is:

BEFORE : blah http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL] blah

AFTER: blah Foo blah

Next time, I'll test out my answers before I give 'em.
In $url, the periods still need to be escaped, too. This is where 
preg_quote() comes in handy.

$url = http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL];;
$url = preg_quote($url);
$code = preg_replace(#$url#,$replace,$code,1);

I hope the OP took notice of the str_replace() remark, too. :)

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

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


Re: [PHP] Help with preg_replace

2004-01-19 Thread John Nichel
John W. Holmes wrote:
In $url, the periods still need to be escaped, too. This is where 
preg_quote() comes in handy.

$url = http://www.foo.com/maxbid/Unsubscribe.php?EmailAddress=[MAIL];;
$url = preg_quote($url);
$code = preg_replace(#$url#,$replace,$code,1);

I hope the OP took notice of the str_replace() remark, too. :)

Well, lookie here.  I've been using php for 6 years now, and favor preg 
over ereg, but never knew about the preg_quote function.  I'm a happy 
camper today.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] help with preg_replace please

2003-03-26 Thread CPT John W. Holmes
 I get the following error:

 Parse error: parse error, expecting `T_VARIABLE' or `'$'' in
 /usr/local/apache/htdocs/lib/lib_string.inc on line 218

 Using this code:
 $str =
 preg_replace(!([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/=])!ei, a
 href=\{$1}://{$2}{$3}\{$2}{$3}/a, $str);

Since you're using the 'e' modifier, the replacement string needs to be
valid PHP code. So, it should start with a variable or a function. A
replacement such as:

'print(a href={$1} .. )'

should work.

I didn't get a chance to answer you original question. I couldn't even get
that regular expression to match links in any tests that I did, but if it's
working for you, that's good. Couldn't you modify the expression to look for
0-60 characters that are not a space, followed by any amount of characters
that are not a space, and only actually match the first 0-60 to use in your
replacement string? Something like:

([^[:space:]]{0,60})[^[:space:]]*

Which will match up to 60 characters in $2 for example, and also allow form
more characters than that, but just not match them. This is assuming what
everyone else said is right and you fix the entire regex to match the preg
syntax...

---John Holmes...


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



[PHP] help with preg_replace please

2003-03-25 Thread Justin French
Hi,

Total newbie on reg exps, and even worse with preg!!!

I get the following error:

Parse error: parse error, expecting `T_VARIABLE' or `'$'' in
/usr/local/apache/htdocs/lib/lib_string.inc on line 218

Using this code:
$str = 
preg_replace(!([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/=])!ei, a
href=\{$1}://{$2}{$3}\{$2}{$3}/a, $str);


Can anyone point to the problem?


The aim is to perform functions on $2  $3.

TIA
Justin French


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



Re: [PHP] help with preg_replace please

2003-03-25 Thread Jason Wong
On Wednesday 26 March 2003 13:59, Justin French wrote:

 Parse error: parse error, expecting `T_VARIABLE' or `'$'' in
 /usr/local/apache/htdocs/lib/lib_string.inc on line 218

 Using this code:
 $str =
 preg_replace(!([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/=])!ei, a
 href=\{$1}://{$2}{$3}\{$2}{$3}/a, $str);

You seem to be using ereg syntax in a PCRE function! Replace them with their 
proper PCRE counterparts.

Eg to match alphanumeric:

 [0-9|a-z|A-Z]  // off the top of my head, untested

etc.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Real Users never know what they want, but they always know when your program
doesn't deliver it.
*/


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



Re: [PHP] help with preg_replace please

2003-03-25 Thread Jason Paschal
what that guy said, or use ereg_replace instead of preg_...





From: Jason Wong [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [PHP] help with preg_replace please
Date: Wed, 26 Mar 2003 14:08:44 +0800
On Wednesday 26 March 2003 13:59, Justin French wrote:

 Parse error: parse error, expecting `T_VARIABLE' or `'$'' in
 /usr/local/apache/htdocs/lib/lib_string.inc on line 218

 Using this code:
 $str =
 preg_replace(!([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/=])!ei, 
a
 href=\{$1}://{$2}{$3}\{$2}{$3}/a, $str);

You seem to be using ereg syntax in a PCRE function! Replace them with 
their
proper PCRE counterparts.

Eg to match alphanumeric:

 [0-9|a-z|A-Z]  // off the top of my head, untested

etc.

--
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Real Users never know what they want, but they always know when your 
program
doesn't deliver it.
*/

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


_
Add photos to your e-mail with MSN 8. Get 2 months FREE*.  
http://join.msn.com/?page=features/featuredemail

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


[PHP] Help with preg_replace() , PLEASE

2003-03-13 Thread fLIPIS
I'm going mad about this. Now, i've got the following text:

- BEGIN TEXT --

Let's see a very simple class sample

?
class CTest
{
  var $variable1;  //Propiedad

  function DoThing()//Método
  {
echo esto es una prueba de clase;
echo una clase es mejor que nada;
  }
}
?

And this was the sample

-- END TEXT ---


I'm using preg_replace() to replace the PHP code qith the result of doing a
highlight_string() to it. So i use this code:

preg_replace(/(.*)(\?.*?\?)(.*)/imse,'\\1'.highlight_string('\\2').'\\3
',$text);

It ouputs this:

?
class CTest
{
  var $variable1;  //Propiedad

  function DoThing()//Método
  {
echo 'esto es una prueba de clase';
echo 'una clase es mejor que nada';
  }
}
?

In colored code, as you might see.

and the weirdest of all: when i use this code:

preg_replace(/(.*)(\?.*?\?)(.*)/imse,''.highlight_string('\\1').''.high
light_string('\\2').''.highlight_string('\\3').'',$text);

It recognizes the \\1 and \\3 strings



Why can't i use then

preg_replace(/(.*)(\?.*?\?)(.*)/imse,''.strtolower('\\1').''.highlight_
string('\\2').''.strtolower('\\3').'',$text]);

or even a simpler

preg_replace(/(.*)(\?.*?\?)(.*)/imse,'\\1'.highlight_string('\\2').'\\3
',$text);




I'm trying to separate the code from the rest of strings, as you might see.
Can anyone help me? I got this far, and i feel it's a very silly thing, but
i can't seem to be able to get it.

Any ideas?



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



[PHP] help with preg_replace()

2002-07-01 Thread Gregor Jak¹a

ive been tryin to find a solution for this problem for some hours now, but i
just dont know how to do it... so i ask for ur assistance. Lemme list some
examples, so u can see what im tryin to do :)
word = word
word = | word |
word = | word |
word = |word |
word = | word|

So if pattern is word it should stay word, if patter is word it should
replace it with |word | and so on as u see from examples... any help or
hints would be helpfull...

thats what i have now: preg_replace(#^[|]?[^\](.*?)[^\]$#i, | \\0 |,
$string); .. but it doesnt work :P

thx in advance !



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




Re: [PHP] help with preg_replace()

2002-07-01 Thread Analysis Solutions

On Mon, Jul 01, 2002 at 01:50:31PM +0200, Gregor Jak¹a wrote:

 word = word
 word = | word |
 word = | word |
 word = |word |
 word = | word|
 
 preg_replace(#^[|]?[^\](.*?)[^\]$#i, | \\0 |, $string);

 preg_replace('/^(|)+?([^]*)?$/', '\\1| \\2 |', $string);

I noticed that when there are quotes, you don't have a space between the  
and the word.  I didn't deal with that.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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