I have XML files as "pages" for my website. Now i faced with some bad situation: when i tried to put some PHP-code inside XML it saves well:
<Content><p>TESTTEXT somemoretext</p>
<p> </p>
<?php echo ('PHP!');?></Content>
BUT! When i echoing it through simple XML everything is ok EXCEPT php-code, for some reason it's commented out now!
<!--?php echo ('1');?-->
Just in case if the saving process is important:
$content = htmlspecialchars($_POST['editor1']);//safe string
$rec = $xml->createElement("Content", $content);//saving
$root->appendChild($rec);
Need your masterpiece help guys!!!
Related
This is a really weird situation that I can't explain.
I use simple HTML DOM and am trying to get the full code of this page:
http://ronilocks.com/
The thing is, I'm getting only part of what's actually on the page.
For instance: look at the page source code and see all the script tags that are in the plugins folder. There are quite a few.
When I check the same with the string I get back from simple HTML DOM none of them are there. Only wp-rocket.
(I used a clean file_get_html() and a file_get_contents() too and got the same result)
Any thoughts?
Thanks!
Edit: Is it possible that wp-rocket (installed on the page being scrapped) knows that the page is being scrapped and shows something different?
include 'simple_html_dom.php';
$html = file_get_html('http://ronilocks.com/');
echo count($html->find('a'));
// 425
I get 425. This looks right to me.
I´m trying a very simple php script which is about calling a json data through api calling on a online https link using MAMP.
However if I use the following code I have blank results:
<?php
$cnmkt = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
$json = file_get_contents($cnmkt);
$fgc = json_decode($json,true);
echo $fgc[1]['percent_change_7d'];
?>
But if i copy/paste the content of the https link into a test.json file locally, substituting the https link with the test.json file on $cnmkt variable, the same exact script works properly.
I know i´m missing something very obvious, if someone could help me that would be very much appreciated, thanks.
Stefano
The script is working fine. I get an expected result of 4.63
Disable your AV/firewall and check again.
I am pretty new to PHP. I am going through a website and am trying to find a source of some of the content and have come across what looks like where the source is, but I cannot decipher the code. Can someone help me understand what this means?
<?php
if (is_file($office_file))
include($office_file);
echo do_shortcode(ob_get_clean());
?>
Thanks!
I have copied your code and added comments that (hopefully) explain what is going on.
<?php
if (is_file($office_file)) // check if $office_file is a valid file
include($office_file); // the check passes, so now include the contents of that file inline
echo do_shortcode(ob_get_clean()); // not enough context to know really what this does, but it looks like its printing the result of parsing 'shortcode' from an output buffer
?>
I'm trying to get the response from database for further usage.eg: userID
However, instead of just getting the userID as the answer,
I'm getting the response from php server with HTML
It shows every HTML tag that I had in my php file,including the comments
EDIT
The php file just simply look like this
<?php
include "Header.php";
include "main.php";
$path = $_SESSION['username'].$_POST['Case_no'];
mkdir($path);
echo $path;
?>
Everything working fine,but the output look something like (let say the $path is "1234")
1234 口 <!--HTML comments and scripts from the webhost-->
If there is any other HTML code in the php,say a link at the front
The result shows
Link 1234 口 <!--HTML comments and scripts-->
Anyway to get rid of this?
The required answer is just merely 1234
ADD ON
I have tried the following example in http://www.hassanpur.com/blog/2010/09/android-development-implementing-a-simple-client-server-model/ (where you can see the whole code)
Instead of getting the "Chirp chirp" as response,
I'm getting sth like "Chirp Chirp 口 " –
Like Mat said, PHP outputs whatever you tell it to output. Don't tell it to output HTML if you don't want that.
if you don't want to output some HTML, persumably written in Header.php and main.php - DO NOT include these files
The problem is solved by using my PC as the server by using the same coding I have shown. The HTML tag and comments is actually generate by the free webhosting side
send "text/plain" header to tell the client that this text shoudn't be interpreted as HTML, because default content type is HTML
header("Content-Type: text/plain");
Try this sample code I threw together to illustrate a point:
<?php
$url = "http://www.amazon.com/gp/offer-listing/B003WSNV4E/";
$html = file_get_contents($url);
echo($html);
?>
The amazon homepage works fine using this method (it is echoed in the browser), but this page just doesn't output anything. Is there a reason for this, and how can I fix it?
I think your problem is that you're misunderstanding your own code.
You made this comment on the question (emphasis mine):
I've never used those utilities before, so maybe I'm doing it wrong but it only seems to be downloading this page: https://www.amazon.com/gp/offer-listing/B003WSNV4E/ref=dp_olp_new?ie=UTF8&condition=new
This implies to me that an Amazon page is appearing in your browser when you run this code. This is entirely expected.
When you try to download https://rads.stackoverflow.com/amzn/click/B003WSNV4E, you're being redirected to https://www.amazon.com/gp/offer-listing/B003WSNV4E/ref=dp_olp_new?ie=UTF8&condition=new which is the intent of StackOverflow's RADS system.
What happens from there is your code is loading the raw HTML into your $html variable and dumping it straight to the browser. Because you're passing raw HTML to the browser, the browser is interpreting it as such, and it tries (and succeeds) in rendering the page.
If you just want to see the code, but not render it, then you need to convert it into html entities first:
echo htmlentities($html);