Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to execute PHP code in echo? I need this to finish my work, but everything I try seems to be fruitless; I often bump to either blank browser page or some errors.
It does not need to be with echo func. Here is example of the code I would like to compile. Just a sample nothing flashy. Echo is just example, I would like to put more complex and advanced code at echo's place but I would like to start from simple stuff like that.
<?php $code = "<?php echo '123'; ?>" echo $code; ?>
That is....an epic fail catastrophe. But for whatever reason, I'm answering... You would need to use eval(). But don't do it. Read here: http://php.net/manual/en/function.eval.php
Perhaps you just need to use include 'path/to/file/with/my/code';. Read here: http://php.net/manual/en/function.include.php
Based on your comments, I think you're actually looking for this:
echo htmlspecialchars(file_get_contents(__FILE__));
That will display the php code that ran. You could search for that line and remove it before displaying. You could even write a function to look at all of the included files and add them to a $variable to be displayed, using the same logic.
Php is only executed on the serverside, so when you try your echo code, you are saying print this code. If you want your code to validate/run logic after it has been server from the server, i would recommend looking into javascript and AJAX requests.
Good luck :)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
From a PHP page (http://example.com/test.php), I would like to call another PHP file located on another web site (http://newsite.example.net/version.php) and passing parameters (var1=123, var2=789). Version.php should do something and return true or false, so I can test the result in test.php (if ($result) ...)
Any short exemple how to proceed and what should be the content of the fileversion.php ?
Regards,
David
Executing a php script in such a way is equivalent to performing an http query. As such, the only result you can expect from the url you call is a http response (plain text, image, json - whatever mime type the page can output).
It can be done for example with file_get_contents() (provided your php configuration allows it) :
$contents = file_get_contents('http://somesite.com/somepage.php?someparameter=somevalue');
You could then process the resulting content text however you like. But you won't ever get direct boolean output. numbers (0 or 1) could be suitable replacements for your needs, however.
Edit:
The version.php might look like this :
<?php if($condition) { echo 1; } else { echo 0; }
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I encounter a strange problem, every time i run my script in php (send a message) and i add a single quote ' it get's doubled. Example sentence: I'd like to know php on expert style it outputs on the one that receive the message: I''d like to know php on expert style. After i reply they are getting doubled again I''''d like to know php on expert style`. What could be the problem?
My file that sends the message looks like this http://pastebin.ca/2495116
and the variable that send the message from what i can see is $m_message
My file that echo's received message looks like this http://pastebin.ca/2495115
This is the variable where the message is being kept and echo'ed on the screen:
<?php echo "" . replace($fetch->message) . ""; ?>
$m_message=str_replace("'","''",strip_tags($_POST['m_message']));
This is what you're looking for.
str_replace(): http://tz1.php.net/manual/en/function.str-replace.php
Changes "'" to "''" every time it finds one in the string strip_tags($_POST['m_message'])
How you ideally want to solve that problem is entirely up to you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
http://www.aliexpress.com/item/NEW-7-Android-2-3-256MB-DDR2-4GB-NAND-Flash-7-inch-tablet-pc/498159194.html - I got this link
Here you can see a buttons: bundle, color
If you click some of them the price will change, but the question is how can I parse that behaviour to my page via php?
The problem is that I can't understand where is javascript code that executes this, or how to find it, maybe someone got ideas about that?
Inspecting that page's source code I can see that the skuProducts variable in javascript contains this information encoded into a JSON-string. You can't really run this javascript code on your webserver, so you'll have to devise another way to get that variable's value - and then you can use json_decode() to get the contents.
Note that changing the amount of items results in an AJAX call to a shipping costs calculator. You could probably simulate that, but I'm not sure that webshop would like that (and it might be illegal).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a html file which has a link to php file. When i run the html file and click on php link source code of page is being shown as i'm not running on server. Is there a way we can check whether it is running on server and show a message like "Please run it on server" instead of showing source code. Searched a lot but didn't find anything on this topic . How can i do this?
No. If there's no PHP interpreter installed there's no way to run PHP script to check that and tell you that you need PHP interpreter installed first to run PHP script....
actually you cannot check this, but you can make some kind of workaround
at the very top of your php file add following code:
<?php
if (false) {
?><script>
alert('php is not on server!!!');
document.location.href='http://MYSERVERADDRESS/';
</script><?php
}
Not really. Sure, for sport I can think of something, but really, you shoudn't be in this situation.
sporthack: what you are trying to do is make non-interpreted code be hidden, and an error be shown. Be sure to realise the non-interpreted code will always be there in your source, so you have to 'hide' it.
Make all content available only via javascript. Also, define a javascript tag with a var via a php echo command.
Then, only show your code when the javascript var is set, otherwise show your desired error. Make sure all your code is 'behind' an include, so you don't show that.
Yeah. this'll take a bit of work to make pretty, so you'd be hard-pressed to even get it off the ground.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Previously I used to add an value like ?help=1 to make PHP know that variable help is used and now it has to show help page. But on a few sites, I have seen they simply use only variables and do not assigned any value (i.e just ?help). Can you please tell me how to do it?
What's wrong with isset($_GET["help"])?
Use PHP's isset function:
if(isset($_GET['help']))
{
echo $_GET['help'];
}
else
{
echo "help is not set";
}
This just means the variable 'help' exists, but has no value. If you maybe left a field blank on a form, it may do this simply so the next script can acknowledge it has no value rather than ignored. It works exactly the same way.