Re: [PHP] Regular expression newbie question, convert this: [::word1\ word2 \ word3::] to : .word1 word2 word3.

2002-06-16 Thread Lance

hi dan,

its because the html text is from user input. and i dont wanna spend too 
much time educating them on coding with php. sometime its a pain trying 
to get them to understand the codes. so i just wanna give them some 
simple commands in php whereby they can happily insert date formats on a 
page. something like what phpBB did on the [url] thingie.

lance

Analysis  Solutions wrote:
 Hi Lance:
 
 On Sun, Jun 16, 2002 at 01:31:45AM +0800, Lance wrote:
 
i was developing an application that will read in the content of a html 
file. and within this html file contains php variables which will be 
replaced using the eval() function with its required value. and within 
this html, i want to be able to run php functions.
... snip ...
eval(\$rs = \span class=\normal\.date(m d 
y).$phpVar/span\;);
 
 
 Why not merge your PHP and HTML straight up like this?
 
 span class=normal?php echo date('m d y') . $phpVar; ?/span
 
 Then, just have the whole HTML file parsed as PHP.
 
 --Dan
 


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




Re: [PHP] Regular expression newbie question, convert this: [::word1 \ word2 \ word3::] to : .word1 word2 word3.

2002-06-16 Thread Analysis Solutions

Lance:

On Sun, Jun 16, 2002 at 03:19:39PM +0800, Lance wrote:
 
 its because the html text is from user input.

So, you're going to run eval() on user supplied input?  Now THAT's 
scarry.

I strongly urge you to rethink what you're doing.

--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




Re: [PHP] Regular expression newbie question, convert this: [::word1\ word2 \ word3::] to : .word1 word2 word3.

2002-06-15 Thread Lance

hi, thanks for the code. i tried. it only worked if the string is simply 
the one i wanna convert. but that particular string is in the middle of 
a long text, and there are multiple occurance, it won't.

however, i did manage to come up with this code that worked. but i 
believe it can be improved on. it will identify all occurance of the 
specified pattern and do the necessary replacement throughout the whole 
string.

preg_match_all(|\[::(.*)::\]|U, $longTxt, $matchedResult);
for ($idx = 0; $idx  count($matchedResult[1]); $idx++) {
$extract = stripslashes($matchedResult[1][$idx]);
$longTxt = str_replace([::{$matchedResult[1][$idx]}::], 
\.$extract.\, $longTxt);
}

lance

Analysis  Solutions wrote:
 Lance:
 
 On Fri, Jun 14, 2002 at 11:41:34PM +0800, Lance wrote:
 
[::word1 \ word2 \ word3::]
to:
.word1  word2  word3.
 
 
 While I don't know if this is really what you need, it does do exactly 
 what you want to do in your example:
 
$Replace['\\']  = '';
$Replace['::']   = '.';
$Replace['[']   = '';
$Replace[']'] = '';
 
$UserInput = '[::word1 \ word2 \ word3::]';
 
echo strtr($UserInput, $Replace);
 
 --Dan
 


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




Re: [PHP] Regular expression newbie question, convert this: [::word1 \ word2 \ word3::] to : .word1 word2 word3.

2002-06-15 Thread Analysis Solutions

Hi Lance:

On Sat, Jun 15, 2002 at 06:54:24PM +0800, Lance wrote:
 hi, thanks for the code. i tried. it only worked if the string is simply 
 the one i wanna convert. but that particular string is in the middle of 
 a long text, and there are multiple occurance, it won't.

Strange.  It should work regardless of length.

Couple things.  Could you please provide an example of the text you're 
trying to convert and explain why you have this weird format and why 
you need the other unusual format.  We may be able to come up with 
something far more straight forward.

--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




Re: [PHP] Regular expression newbie question, convert this: [::word1\ word2 \ word3::] to : .word1 word2 word3.

2002-06-15 Thread Lance

hi,

i was developing an application that will read in the content of a html 
file. and within this html file contains php variables which will be 
replaced using the eval() function with its required value. and within 
this html, i want to be able to run php functions. however, due to the 
fact that characters need to be escaped so that eval() can process it, i 
have to make use of addslashes() to escape all  that are embedded in 
the html file.

with the  escaped, eval() will be able to work and evaluate the php 
variable and instead of:

eval(\$rs = \span class=normal$phpVar/span\;); (won't work)

it will now be:
eval(\$rs = \span class=\normal\$phpVar/span\;); (work)

and to call a date() function on the above text, this format will work:

eval(\$rs = \span class=\normal\.date(m d y).$phpVar/span\;);

since the text that is passed into eval() came from a html/php/inc 
(whatever you name it) file, there is no way you will know that a 
particular text is in fact a php function.

so i thought of prefixing and suffixing php function with [::date(m d 
y)::] and it will be helpful in the sense that the application will 
know that oh, this is a php function, i need to .  . it so that eval 
will not throw me an error.

with that, now the html file's content will be something like:
span class=normal[::date(m d y,$phpVar)::]/span

after using addslashes(), it will be:
span class=\normal\[::date(\m d y\,$phpVar)::]/span

for the above text, in order for eval() to parse correctly, it has to be 
in this format:
eval(\$rs = \span class=\normal\.date(m d y,$phpVar)./span\;)

and there is always a chance that the html text could contain more than 
1 block of [:: phpfunction ::]

thats why i came up with that piece of code to convert the text to a 
string that eval will be able to understand. and at the end of it, i 
will be echoing $rs to display the final result.

you probably will wonder why dont i use include() and require()? that 
way, php will be handling all the above without requiring additional 
work. however, due to the way the result has to be handled, i couldn't 
use include nor require.

lance


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




Re: [PHP] Regular expression newbie question, convert this: [::word1 \ word2 \ word3::] to : .word1 word2 word3.

2002-06-15 Thread Analysis Solutions

Hi Lance:

On Sun, Jun 16, 2002 at 01:31:45AM +0800, Lance wrote:
 
 i was developing an application that will read in the content of a html 
 file. and within this html file contains php variables which will be 
 replaced using the eval() function with its required value. and within 
 this html, i want to be able to run php functions.
 ... snip ...
 eval(\$rs = \span class=\normal\.date(m d 
 y).$phpVar/span\;);

Why not merge your PHP and HTML straight up like this?

span class=normal?php echo date('m d y') . $phpVar; ?/span

Then, just have the whole HTML file parsed as PHP.

--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




Re: [PHP] Regular expression newbie question, convert this: [::word1 \ word2 \ word3::] to : .word1 word2 word3.

2002-06-14 Thread Analysis Solutions

Lance:

On Fri, Jun 14, 2002 at 11:41:34PM +0800, Lance wrote:
 
 [::word1 \ word2 \ word3::]
 to:
 .word1  word2  word3.

While I don't know if this is really what you need, it does do exactly 
what you want to do in your example:

   $Replace['\\']  = '';
   $Replace['::']   = '.';
   $Replace['[']   = '';
   $Replace[']'] = '';

   $UserInput = '[::word1 \ word2 \ word3::]';

   echo strtr($UserInput, $Replace);

--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