note 63591 added to function.strtr

From: Date: Fri, 24 Mar 2006 18:10:29 +0000
Subject: note 63591 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-106538@lists.php.net to get a copy of this message
I'm not sure if it has already been mentioned but I had one hell of a time working with the dollar sign character and the shell (bash). Basically a dollar sign is a special char in the terminal so there is a need to replace them in all your strings. There's a quite a few gotchyas though. Ex 1 ** DOES'NT WORK <?php $mystring = 'I want to make lots of $$ CACHE $$!'; $mystring = str_replace($mystring, '$', '/$'); // output: '//$' ?> Ex 2 ** ALMOST THERE... <?php $mystring = 'I want to make more $$ CACHE $$!'; $mystring = strtr($mystring, '$', '/$'); // output: 'I want to make more // CACHE //!' ?> Ex 3 ** GOT IT! <?php $mystring = 'I want to make the most $$ CACHE $$!'; $mystring = strtr($mystring, array('$', '/$')); // output: 'I want to make the most /$/$ CACHE /$/$!' ?> ---- Server IP: 216.235.15.211 Probable Submitter: 24.84.32.26 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strtr.php Edit -- http://master.php.net/note/edit/63591 Del: integrated -- http://master.php.net/note/delete/63591/integrated Del: useless -- http://master.php.net/note/delete/63591/useless Del: bad code -- http://master.php.net/note/delete/63591/bad+code Del: spam -- http://master.php.net/note/delete/63591/spam Del: non-english -- http://master.php.net/note/delete/63591/non-english Del: in docs -- http://master.php.net/note/delete/63591/in+docs Del: other reasons-- http://master.php.net/note/delete/63591 Reject -- http://master.php.net/note/reject/63591 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106538) next »