I tried the following coding for a 'UIWebView:
let kapitel3 = "<html><head><title>Chapter 1</title></head><body><h1>This is a title!</h1></body></html>"
This HTML code works fine and "UIWebView" shows this code. But if I try to insert a PHP code within the HTML code like this:
let kapitel3 = "<html><head><title>Chapter 1</title></head><body><h1>This is a title!</h1><?php print \"Hello world!\";?></body></html>"
Then the PHP code won't be showed. Why doesn't 'UIWebView' translate this PHP code <?php print \"Hello world!\";?>?
Is it not possible to integrate PHP code in a String like above?
Thanks for any hints!
UIWebView is only a simple web-browser...
You can't use php like that if you don't have a local webserver with a php interpreter installed!
You could load a php page from a remote url but your phone must have an active internet connection...
Possible local solution:
You can't use php locally, but in a UIWebView you can still use javascript!
I don't know what you are trying to do...but if you need your app to work offline (with local files) using php is the wrong approach.
Related
On this server, I can use both .cfm and .php files. Both types will be parsed, as expected.
However, I want .cfm files to be parsed for php, as well. For example,
//test.cfm:
<cfoutput>hello from cf</cfoutput>
<?php echo 'hello from php'; ?>
// outputs the php, verbatim, without processing :(
I know that I can change the php config, to parse .cfm. I dont know what order the parsing will take place or any other pros and cons, tricks and tips.
The goal here is that I want to wrap php (which i know well) into a cfm file (much less experience). The cfm file will be in an admin section, which automatically checks the user auth, and includes other cf files.
So, it seems to me that if coldfusion parses the file (checking the user-auth and all that), then hands it over to php, that would be the process that I am looking for.
This has been done:
See: http://www.barneyb.com/barneyblog/projects/cfgroovy2/
Most of the documentation has mixing ColdFusion and Groovy, but other languages can be mixed in too.
Example code:
<cfimport prefix="g" taglib="engine" />
...
<h2>Run some PHP (via Quercus)</h2>
<cftry>
<g:script lang="php">
<?php
$variables["myArray"][] = "Pretty Happy People wrote PHP.";
echo "<pre>";
var_dump($variables["myArray"]);
echo "</pre>";
?>
</g:script>
<cfcatch type="CFGroovy.UnknownLanguageException">
<p>Quercus needs to be added to your classpath for the PHP example to work</p>
</cfcatch>
<cfcatch type="any">
<p>Error running PHP code: #cfcatch.message#</p>
<p>#cfcatch.detail#</p>
</cfcatch>
</cftry>
Source: https://ssl.barneyb.com/svn/barneyb/cfgroovy2/trunk/demo/index.cfm
It will depend on the ColdFusion Application Server, what it supports and what level of interoperability you want. Generally if you want to be able to mix variables across statements, then you need to share the ColdFusion pageContext and make sure that php variables are written and updated. I don't believe that the example above does this, but I am happy to stand corrected. The other alternative is to called ColdFusion from PHP, again using Quercus. These 2 articles will help you do this. The first shows how to call Java from PHP, the second how to call ColdFusion from Java.
http://quercus.caucho.com/quercus-3.1/doc/quercus.xtp#Instantiatingobjectsbyclassname
http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSe61e35da8d318518-106e125d1353e804331-7ffb.html
Firstly create a ColdFusion component that can render ColdFusion dynamically
<cfcomponent displayname="ColdFusion renderer" output="false">
<cffunction name="render" returntype="'String' or 'Any'">
<!---
Do something with the coldfusion code here e.g:
write to a file using <CFFILE> and then <CFMODULE> or <CFINCLUDE>,<CFSAVECONTENT> it
or if the ColdFusion is all script, use the evaluate() function
--->
</cffunction>
</cfcomponent>
the invoke the component in PHP, via Java, using the CFCProxy
<?php
function cfml($code)
{
$cfc = new Java("coldfusion.cfc.CFCProxy", "path/to/cfc/above");
$cfc.render($code);
}
echo 'hello from php';
cfml(<<<EOT
<cfoutput>Hello from CF</cfoutput>
EOT
);
?>
I'm learning PHP coding and I can't solve this problemIt's includes the variables and the endlines.
I'm new to the language.
There is no other issue, fix your xampp problem, put your project in xampp > htdocs folder, save your file with .php extension and go to browser write http://localhost/project/page.php
Update: You are calling POST values, meaning a form (similar to a login form) has to send the values of tireqty, oilqty, and sparkqty to that page.
So you generally want to start a .php file with <?php at the very top. I would recommend doing a simple example like this:
<?php
echo '<p>1</p>';
?>
<p>2</p>
Or, change your file to reflect .html instead. You should be able to still have the php run properly there like this:
<p>1</p>
<?php
echo '<p>2</p>';
?>
If this doesn't work, please update your question to provide:
Operating System
What program you're using
What browser you're using
What version of PHP you're using
Any other information about your system
php html server
I am trying to display the PHP source of a file inside a page. I am using show_source function in this way:
<?php
$nomefile = $_REQUEST['nome'];
show_source($nomefile);
?>
When I try this code on my local PC (using USBWebserver v8.6), it works smoothly, displaying the PHP code of the page. But when I try it on my remote webserver (Altervista), I only get an empty page.
I even try to substitute variable $nomefile with name "visite.php", which is the name of a file residing in the same folder, but still I get no result? I try with echo show_source(...), but no result again.
Is there an error in my code? Or maybe show_source is not compatible with all version of PHP? Is there any easy alternative?
Thanks a lot
Giancarlo Perlo - Italy
I've some strange issues with some php code.
if ($user->userType=='admin'){
If I use the above command, the php engine just stop interpreting and display the code in plain text on my browser. On the other hand if I use the below method it works:
if ($user['userType']=='admin'){
Again here also:
$_SESSION['currentUser']->id
If I use the above code it just displays the rest of code as plain text:
id); // fail user }else{ $authentication="failed"; $noAuthPresentation="loginForm"; }
Why this is happening? It's a big project and I don't want to change every line where there is an occurrence of ->.
Do I need to change some setting somewhere? I'm using WAMP server with php 5.5.12.
Any help ? Thanks!
You're mixing up types, user is an array, and not an object. Something in your php config is doing something strange to your error display it seems. Right click on the page that has the errors, and view source if possible.
Does login.php contain html and php code by chance?
I'm not entirely sure the wording for the title is correct, but what I'm attempting to do is run and execute PHP files from within the Lift framework.
I'm not after any url queries to a PHP file residing on a server, more interested in somehow getting the PHP runtime working through my Scala/Lift app.
Use case: I have my app packaged into a .war file, I host this via a cloud provider. I upload code snippets to said app which then runs the php file and does whatever necessary.
I've seen various posts regarding Bianca but am hoping to keep this setup light and require only the PHP binary itself and a little code to get it flying.
Thanks in advance, please let me know if you need me to elaborate :)
“Never say never, because limits, like fears, are often just an
illusion.”
― Michael Jordan
What you really need is an open source (GPL), embeddable, full PHP 5 implementation, written entirely in Java!
Caucho's Quercus PHP Java runtime is just that, and it will let you run PHP within a Java app without external libraries or native code.
Below is a Quercus-PHP-in-Java code sample I found in this answer
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
String phpCode = "<?php $foo = strlen('abc'); print $foo; return 'yikes'; ?>"; //PHP Code as String
Object o = engine.eval(phpCode);
System.out.println(o);
It should be little effort to convert this code to idiomatic Scala. Obviously, the 'phpCode' variable could be constructed from external PHP file contents etc.
Let us know how you get on ;-)
That's a bit of an odd requirement, but if it's what you need to do, you can use a ProcessBuilder to execute and interact with your PHP script from the command line.