Creating an actual XML RSS feed in PHP - php

I currently have a dynamic RSS feed that looks like this.
This is fine for importing into feed readers, but now I need one that can work with my jQuery plugin. As a result, I'm trying to create something that looks like this.
I may be wrong, but it seems that the only difference is that former is a PHP file where the second is actual XML.
How would I go about creating the XML version?

You would need to change the content type headers to "application/xml". In php, this is done by
header('Content-type: application/xml');
It seems somewhere your scripts is actually setting the headers to "Content-Type:application/rss+xml;" so you may only need to replace this line.
I'm not sure why this would actually matter to your jquery plugin, but at the very least, the example you gave uses the same headers.

Related

how do I find out what php function from Wordpress is generating blocks of HTML using browser inspector?

I'm developing a Wordpress site, which I'm fairly new to. I'm not sure if this is a stupid question or not but I haven't been able to return any decent google results regarding this. Anyway, is there a way to find out what PHP function is generating a piece of HTML code using a browser code inspector like Chrome's? Thanks!
No.
Once the data arrive to the browser, all the PHP code have been processed and you can't know what part of PHP generated which part of the HTML code.
No - not without modifying the php code to enable some kind of debugging. Chrome can only give you information about the received html document on the client side (you). But php code gets parsed server side.
You kind of can:
Download a copy of the theme and plugins folder
Open the page on your site that you want to find the function for.
Find a div/class that is specific to section e.g. <article>
Open a text editor like notepad++ (one that will allow you to search through multiple files at ones)
Use the find feature of chosen text editor and search for the div/class
The result will show you a list of pages where that term is.
Look through those pages for the function you are looking for (it might take a few goes)
The above it is a bit of a roundabout way of doing it, but I think other than looking through each file separately, it is you next best way.

Stop PHP parsing but output the rest of the file

I'm developing a web application where an html page is created for the user. The page could include anything that the user puts in it. We take these pages and add a little PHP at the top to check some things before outputting the actual html. It would look kind of like this:
<?php
require 'checksomestuff.php';
// User's html below
?>
<html>
<!-- user's html -->
</html>
Is there a way to stop PHP from parsing anything after my require? I need the html to be outputted, but, since the user can add anything they want to the html, I don't want any user-added PHP to be executed. Obviously that would be a security issue. So, I want the user's html to be outputted, but not parse any PHP. I would rather not have to put the user's html into another file.
One sensible way would be to offload the user created content to another file and then you should load this file (in your main php file) and output it as is - without parsing it as PHP.
There are many other ways to do this but if creating another file does the job for you then thats probably the best way forward.
UPDATE: Really must read last line of question!
You could encode the html into a variable using base64 encoding which you then just print out the decoded string.
If you don't store the file data in a php file, say n a txt or html file, the php won't be evaluated.
Alternatively you could read the file via file_get_contents() or by some other means which doesn't involve evaluating php.
Though I'm still tempted to ask why you want to do this (particularly this way), it sounds to me like one of the only things that can help you is the special __halt_compiler() function...
That should prevent it from executing the rest of the page, and may or may not output the rest of it. If not, well, read the first (and currently only) example in the PHP's manual for that function (linked above) for how to do it manually.
The only trouble I see with this method is that you'd probably have to have that code in every file you want to do this for, after your require.

Extracting Data From Remote XML & Creating Wordpress Post

I've been searching for some time to figure out how to extract data from a remote XML file and then create a post automatically with the parsed XML data. I have figured out the functions to create a post using cURL/PHP but I'm not sure how to pull data from an XML file, put that data into strings and then apply those strings to a newly created post. Also dupe protection would be nice.
If anybody knows a good starting point for me to learn or has written something ealready that could provide useful assistance then that would be great. Thanks guys
PHP has a wide variety of XML parsing functions. The most popular around here is the DOM. You can use DOM functions to find the specific XML tags you're interested in and retrieve their data.
Unfortunately you did not provide an example of the XML you're trying to work with, otherwise I'd post a brief example.
If you have to stay with xml format using php you use something with this here. If you can change the format to basic csv text you could try using wordpress plugin here.
Also php has a function for csv files called fgetcsv , so I would say get the information needed from your file.
Pass to a variable and than use wp_insert_post to create a post. Put it all in a while or foreach loop and should work fine - Or try the plug-in first.
As for duplicate content, perhaps you could pass the information in an array and then use array_unique to delete any duplicates (just off the top of my head theres probably a better way or function out there).

Anyone able to read ning's json export files using PHP

I have a client's JSON files that he got from the NING exporter. I'm trying to load the data into PHP but seems like the json isnt properly formatted or something. SO PHP is not able to parse the JSON. I also used another PHP class to do it but that did not work either. Below is the content of one of the files
([{"id":"2492571:Note:75","contributorName":"16szgsc36qg2k","title":"Notes Home","description":"Welcome! To view all notes.","createdDate":"2008-11-14T08:44:58.821Z","updatedDate":"2008-11-14T08:44:58.821Z"}])
Help appreciated!
The parens at the beginning and end are not valid in JSON. It should parse after stripping those.
The JSON file from NING exporter is not properly formatted. For some reason, some commas are missing and you have '}{' pattern, instead of '},{' and the first and the last char is not correct.
You can write a small routine to pre-parse the file and fix those problems and some others that might appear or you can take a look at the code of this Wordpress plugin http://wordpress.org/extend/plugins/import-from-ning/ and copy the routine that fix the json file.
If you'd like to move your Ning data to another platform, you could consider Discourse. There is already an importer for it.
If you don't want to use Discourse, you can still use the (Ruby) importer source code to see how to parse the JSON file.

Passing variable to Google Charts URL

This is probably something really simple, however I am quite new to PHP, and havent done any HTML in years.
I need to get a PHP variable filled with an array of figures into Google Charts. My code for this so far is:
<img src="http://chart.apis.google.com/chart?
&chs=340x175
&chd=t:<?=$filedetail[1]?>
&cht=lc
&chtt=Test
">
However, Google reports an error, as it stops at the ?=$filedetail[1] for some reason. It doesnt seem that reading the variable is the problem, more that the API simply cant read past the start of the PHP tags.
Thanks,
Rob A.
EDIT: I have managed to make Google accept the URL, however now it is not showing anything on the chart, as its filling in the &chd=t: field with instead of the figures within that variable.
The URL reads like this:
http://chart.apis.google.com/chart?&chs=340x175&chd=t:%3C?=$filedetail[1]?%3E&cht=lc&chtt=Test
If oyu say Google is complaining about the ?=$filedetail, chances are you are doing this in a file that is not being parsed by PHP, for example a file that ends with .html or .htm.
You can see whether this is the case by looking into the page's source code in the browser. If you see the PHP command in the source as you wrote it above, the PHP code was never executed.
The easiest way to fix that, if that's the problem, would be to switch to a .php file extension.
In URLs, literal & should be written as &
Edit: And you can't do ?&chs -- it should be ?chs. The line breaks are probably going to break the URL too...

Categories