[pmwiki-devel] FW: $12.50 -> .50 var problem

J. Meijer commentgg at hotmail.com
Tue Apr 10 08:57:03 CDT 2007


Jason is right.   $v = preg_replace('/\$[0-9]/', '\\\\$0', $v);Should work. $12 to him. To also protect against \\12.50in your data the best I can do is follows./jm<?php   # you need this while developing!error_reporting(E_ALL);  # init test vars$v='One $, $12.50 \\12.50 \\\\12.50 \1';    print $v;  $ff='something';$newpage['text']='text with (:something: value:) embedded';  # the essential bit $v=str_replace(array('\\','$'),array('\\\\','\$'),$v);if (strpos($newpage['text'], "(:$ff: ") !== false)  # not needed at all, complicates your code (Kathryn is your friend)  $newpage['text'] = preg_replace("/\\(:$ff: (.*?):\\)/s", "(:$ff: $v:)", $newpage['text'], 1);    print " <br/>\n$newpage[text]";  exit;From: commentgg at hotmail.comTo: editor at fast.st; pmwiki-devel at pmichaud.comSubject: RE: [pmwiki-devel] $12.50 -> .50 var problemDate: Tue, 10 Apr 2007 13:15:30 +0000






I'm now busy resolving your problem. Before starting there are a few problems with your code upfront:> if (strpos($newpage[text], "(:$ff: ") == true) $newpage['text'] =  preg_replace(>            '/\\(:'.$ff.': (.*?):\\)/s',  "(:$ff: $v:)",  $newpage['text'], 1);1. Do this in anything you are developing:     error_reporting(E_ALL);    # let PHP help you2. strpos returns either false or a number. Don't test for 'true', test for ' !== false ' (note this isn't ' !=false ' )strpos($newpage[text], "(:$ff: ") == true    3. Use quotes as in $newpage['text']  (point 1 would have helped you here). Now getting to the regex part. Seems like you have to preg_quote()/jm > > On 4/9/07,  The Editor  wrote:> The following is causing me huge problems.  Been working on it for> hours--and seem to have finally narrowed it down to here...> > if (strpos($newpage[text], "(:$ff: ") == true) $newpage['text'] =  preg_replace(>            '/\\(:'.$ff.': (.*?):\\)/s',  "(:$ff: $v:)",  $newpage['text'], 1);> > It's part of a routine that checks to tell if a certain (hidden) text> variable exists and if it does, it replaces the current value with the> new value ($v).> > All works fine generally--except when $v has a $ in it it thinks its a> variable that doesn't exist.  So $12.50 gets changed to .50.  And that> throws me off.> > Can anyone suggest a fix for this bedeviling little bug...> > Cheers,> Dan> > PS.  I'm pretty sure $ff and $v are the correct values going into this> process. Just missing the $12!> > _______________________________________________> pmwiki-devel mailing list> pmwiki-devel at pmichaud.com> http://www.pmichaud.com/mailman/listinfo/pmwiki-devel> _________________________________________________________________> It’s tax season, make sure to follow these few simple tips > http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTips.aspx?icid=WLMartaglineLive Search Maps – find all the local information you need, right when you need it. Find it!

_________________________________________________________________
Your friends are close to you. Keep them that way.
http://spaces.live.com/signup.aspx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-devel/attachments/20070410/e5d2d903/attachment-0001.html 


More information about the pmwiki-devel mailing list