Re: [PHP] Re: preg_replace problem

2009-06-14 Thread Mark Kelly
Hi.

On Saturday 13 June 2009, Al wrote:
 I may not have been very clear. Feed it just  test   with the
 quotes. You should get back, test the same as you gave it.   Instead,
 I get back quote;testquote;

Like Shawn, I have tried your code in isolation and only get the expected 
results. I looped it over a few test values:

?php
$valueList = array('','test','testtest','testamp;test');
echo pre\n\n;
foreach ($valueList as $value) {
echo Before: $value\n;
$value=preg_replace(%(?!amp;)%i, amp;, $value);
echo After: $value\n\n;
}
echo '/pre';
?

outputs (ignoring pre as that was just to remove the br / for easy 
reading):

Before: 
After: 

Before: test
After: test

Before: testtest
After: testamp;test

Before: testamp;test
After: testamp;test

The only conclusion is that something else in your code is converting the 
quotes. Have a look around.

HTH

Mark

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



Re: [PHP] Re: preg_replace problem

2009-06-14 Thread Andrew Ballard
On Sat, Jun 13, 2009 at 5:16 PM, Aln...@ridersite.org wrote:


 Al wrote:

 This preg_replace() should simply replace all  with amp; unless the
 value is already amp;

 But; if $value is simple a quote character [] I get quote. e.g.,
 test = quote;testquote;

 Search string and replace works as it should in Regex_Coach.

 echo $value.'br /';
 $value=preg_replace(%(?!amp;)%i, amp;, $value);
 echo $value;

 I tried using \x26 for the  in the search string; didn't help.

 This seems too obvious to be a bug. Using php5.2.9

 Al...

 I erred when I keyed this message. The But, should be as, without the
 e on quote. Which is an HTML entity for quote.

 But; if $value is simple a quote character [] I get quot. e.g.,
  test = quot;testquot;


The regex that you posted won't replace an actual quote character at
all. Are you sure you aren't running the value through something like
htmlspecialchars() before it's getting into your regexp?

Andrew

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



[PHP] Re: preg_replace problem

2009-06-13 Thread Shawn McKenzie
Al wrote:
 This preg_replace() should simply replace all  with amp; unless
 the value is already amp;
 
 But; if $value is simple a quote character [] I get quote. e.g.,
 test = quote;testquote;
 
 Search string and replace works as it should in Regex_Coach.
 
 echo $value.'br /';
 $value=preg_replace(%(?!amp;)%i, amp;, $value);
 echo $value;
 
 I tried using \x26 for the  in the search string; didn't help.
 
 This seems too obvious to be a bug. Using php5.2.9
 
 Al...

Your code works for me, unless I'm misunderstanding the problem.  With
the following:

$value = quote;testquote;;

I get:

quote;testquote;br /
amp;quote;testamp;quote;

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: preg_replace problem

2009-06-13 Thread Al



Shawn McKenzie wrote:

Al wrote:

This preg_replace() should simply replace all  with amp; unless
the value is already amp;

But; if $value is simple a quote character [] I get quote. e.g.,
test = quote;testquote;

Search string and replace works as it should in Regex_Coach.

echo $value.'br /';
$value=preg_replace(%(?!amp;)%i, amp;, $value);
echo $value;

I tried using \x26 for the  in the search string; didn't help.

This seems too obvious to be a bug. Using php5.2.9

Al...


Your code works for me, unless I'm misunderstanding the problem.  With
the following:

$value = quote;testquote;;

I get:

quote;testquote;br /
amp;quote;testamp;quote;



I may not have been very clear. Feed it just  test   with the quotes. You 
should get back, test the same as you gave it.   Instead, I get back 
quote;testquote;


Like wise, if I give it just a single quote [] I get back [quote;]

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



[PHP] Re: preg_replace problem

2009-06-13 Thread Al



Shawn McKenzie wrote:

Al wrote:

This preg_replace() should simply replace all  with amp; unless
the value is already amp;

But; if $value is simple a quote character [] I get quote. e.g.,
test = quote;testquote;

Search string and replace works as it should in Regex_Coach.

echo $value.'br /';
$value=preg_replace(%(?!amp;)%i, amp;, $value);
echo $value;

I tried using \x26 for the  in the search string; didn't help.

This seems too obvious to be a bug. Using php5.2.9

Al...


Your code works for me, unless I'm misunderstanding the problem.  With
the following:

$value = quote;testquote;;

I get:

quote;testquote;br /
amp;quote;testamp;quote;



I tried IE8 thinking it could be a weird browser bug. Same error.

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



[PHP] Re: preg_replace problem

2009-06-13 Thread Al



Al wrote:
This preg_replace() should simply replace all  with amp; unless 
the value is already amp;


But; if $value is simple a quote character [] I get quote. e.g., 
test = quote;testquote;


Search string and replace works as it should in Regex_Coach.

echo $value.'br /';
$value=preg_replace(%(?!amp;)%i, amp;, $value);
echo $value;

I tried using \x26 for the  in the search string; didn't help.

This seems too obvious to be a bug. Using php5.2.9

Al...


I erred when I keyed this message. The But, should be as, without the e 
on quote. Which is an HTML entity for quote.


But; if $value is simple a quote character [] I get quot. e.g.,
 test = quot;testquot;

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



[PHP] Re: preg_replace problem (or possibly bug)

2006-03-08 Thread Rafael
	What I see in the page you sent is a [url] bbcode-tag that is not 
closed (i.e. it has no [/url] or it's not displayed)


	If that's not the problem, could you send some example that isn't 
working (and some others that are working)


Michael wrote:

I am currently writing a forum system, but at the moment I have a bug
that no one can seem to get to the root cause of. Basically I am using
preg_replace with the pattern as '\[url=(.*?)\](.*?)\[/url\]'is.
However for most links it works fine but for others it just doesn't
render the bbcode to a link, we were trying to get to the root cause
of it here 
http://michael-m.co.uk/forums/index.php?action=view_topicid=31page=1
but we failed. I'm not really that good with regular expresions so
that might explain why. Also we had never noticed these problems until
about 3 days ago, but I see no reason why it could have started. All
help will be greatly appreciated, you may use the username php and the
password php to log on to do your own tests but please keep the
testing to the topic (and the spam forum if necessary).

Many Thanks,
Michael Mulqueen
michael-m.co.uk

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

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



[PHP] Re: preg_replace problem

2006-03-01 Thread Rafael
	Is there any special reason why you want to solve this with regular 
expressions?  As far as I see, there's a couple of problems with your code,

a) $file = dog.txt  should be  $file = 'dog.txt',
b) $getOldValue has the _array_ resulting of parsing the INI file,
   hence you should write $getOldValue, since it's the complete file
   (I won't say anything about performance),
c) you're using a regular expresion to increment the value in a
   specific key/index, and you don't need regexp for that, and
d) you're not saving the whole file, only the setting (entry) for
   today, hence you overwrite the file and leave only today = n

What do you think of something like this (a bit changed):
$file= 'dog.txt';
$today   = date(Ymd);
// we read the file,
$getOldValue = parse_ini_file($file);
// set or increment the value in $today key,
   @$getOldValue[$today] ++;
// and write back the whole INI file
// note: what we have is an array, not a string
$str_ini = '';
foreach ( $getOldValue as $date = $value ) {
$str_ini .= $date = $value\n;
}
file_put_contents($file, $str_ini);

Benjamin Adams wrote:

$file = dog.txt;
$today = date(Ymd);

function incDate($new, $date){
//$date = settype('int');
return $new.($date++);
}

$getOldValue = parse_ini_file($file, 1);
$newValue = $getOldValue[$today] + 1;
$oldDate = $today .  = . $newValue;
$newDate = preg_replace('/(\d+\s\=\s)(\d+)/ie', 'incDate($1,$2)',  
$oldDate);

file_put_contents($file, $newDate . \n);

This works with one file but with multi lines I'm having trouble:
if the file has:
20060301 = 34
20060302 = 3
the file after script will be:
20060302 = 4

I want it to preserve the previous lines
so output should be:
20060301 = 34
20060302 = 4

Help would be great, thanks
Ben

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

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