You are here: Re: How do I quote this in php? « All PHP « IT news, forums, messages
Re: How do I quote this in php?

Posted by Dave (from the UK) on 05/21/06 15:55

Gazza wrote:
>
>
> Dave (from the UK) mumbled the following on 21/05/2006 03:39:
>
>> MemoryConstrained[ FactorInteger[141],100000000,"Too Much RAM Aborting"]
>
>
>> http://www.althorne.org/test.txt
>
>
> Looks like you're echoing
> MemoryConstrained["FactorInteger[141]", 100000000, "Too Much RAM Aborting"]
>
> Does the first argument need to be in quotes?

It depends on what the command contains, which is a real pain in the
****. (I have sussed the other program, thanks to your help).

The web page is supposed to interface to a program 'Mathematica' which
has hundreds of commands, but a few examples are:

1) 1+10
2) FactorInteger[141]
3) ReadList["/etc/passwd",String]
4) $OperatingSystem

The contents of the web page are read into $cmd via the php script.

Now the first two Mathematica commands (1+10 or FactorInteger[141]) will
work no matter how you quote $cmd. But to get the double quotes through
in the

ReadList["/etc/passwd",String]

I need to quote like this:

$cmd=$_POST['input_data'];
$handle = popen("echo TimeConstrained[ MemoryConstrained[\"$cmd\",$maxram,

note now $cmd is quoted in the second line.

But to get a Mathematica command with a $ in it (such as
$OperatingSystem) to the program, it needs to be done as

$handle = popen("echo TimeConstrained[MemoryConstrained['$cmd',

So far, I can find no way of putting all valid Mathematica commands into
a web page and getting them passed to Mathematica. The best I can do, is
have two submit buttons, one of which works if there is a " and the
other if there is a $, but neither submit button will work for both.
Needless to say, if the command had both a $ and a " then I have no way
to run it.

> Alternatively, (and this makes more sense), when passing the command to
> cat, the quotes are removed, right? Leaving you with Factor...and not
> "Factor...".

Yes.

> Therefore, to keep the abort string as one, you'll need to
> double-quote it. Not sure of the exact syntax, perhaps \"\"Too
> much...\"\" ? You may or may not need to stripslashes() at some point.

Thanks. I played a bit, and found that:

'\"Too Much RAM has been used so we are Aborting\"'

did the trick.

> Sorry it's not quite a full answer, but it might point you or someone
> else in the right direction!

Yes it did thanks.

Anyone else care to know how I might do the rest?

Here is my latest version, with the two submit buttons.

http://www.althorne.org/witm/witm.php

(the code is at http://www.althorne.org/witm/witm.txt)

Anyone care how to change it so one submit button will work for all
cases? This does *not* call Mathematica, as it is a dangerous program to
call on a public access web server. But the bits the standard input to
Mathematica can be seen there

http://www.althorne.org/witm/stdin.txt

which should have the $ and " in the right places. So far I can't seem to.
--
Dave K MCSE.

MCSE = Minefield Consultant and Solitaire Expert.

Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@domain. Hitting reply will work
for a couple of months only. Later set it manually.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация