I've got a PHP script that searches my Joomla DB for the introtext field in #_content and returns the results as a json_encoded string.
Not sure why, but some of the introtext feilds are NULL in the JSON string (e.g. {"introtext":null},{"introtext":null} ) when they clearly aren't/should not be. Some return the text just fine.
Here's my script . . .
<?php
/* Connect to database */
$DB_HostName = "**";
$DB_Name = "**";
$DB_User = "**";
@mysql_connect($DB_HostName,$DB_User) or die ('Could not connect');
@mysql_select_db($DB_Name) or die ('Could not find database');
$result = mysql_query ("SELECT introtext FROM **_content") or die (mysql_error());
$records = array();
while ($row = mysql_fetch_assoc($result)) {
$records[] = $row;
}
echo json_encode($records, JSON_HEX_TAG);
mysql_close();
?>
The DB introtext field contains HTML tagged text. The query I've written above succeeds just fine when entered directly in the phpMyAdmin tool for the DB. The introtext field includes some blank entries (e.g. <p></p>)
but the vast majority have HTML tagged text included. The query returns results for all introtext fields in the *_content table.
UPDATE
I've discovered my issue is with the json_encode function. This function only works with UTF-8 encoded data, and not everything in my introtext is correctly encoded in this format. If not properly encoded, it will return NULL
. The solution is to run my array through a function in my PHP script that will encode things properly before returning the json_encoded data.
See this link for some options in the comments: http://www.php.net/manual/en/function.json-encode.php
Now I just need to strip all the HTML tags (working with strip_tags to try and get this done) so I can have just the article text to work with. Any suggestions on how best to do this is appreciated.