RSS title tag not displaying data - rss

For some reason, the RSS < title > </ title > tag is not working in the code below. I want the $hdline there, but it just doesn't appear, while using < author> or < source> instead does.
$hdline = $row['hdlinestr'];
$link = $row['urlstr'] ;
$category = $row['category'] ;
// echo $hdline ;
echo "<item>" ;
echo "<title>Title</title>" ;
echo "<source>" . $hdline . "</source>" ;
echo "<link>" . $link. "</link>" ;
echo "<category> <b>" .$category . "</b><br></category>";
echo "</item>";
Here is output. sample RSS code

Related

PHP SQLite3 query not displaying all rows

I have a PHP script show below that queries for all rows. The result set only shows one row even though there are more.
mbrlist.php
`<?php
$html = "";
class MyDB extends SQLite3
{
function __construct()
{
$this->open('privdata/helpseekers.db');
}
}
$db = new MyDB();
if ( !$db )
{
echo $db->lastErrorMsg();
}
else
{
$rows = $db->query("SELECT COUNT(id) as count FROM accounts");
$row = $rows->fetchArray(SQLITE3_ASSOC);
$numRows = $row['count'];
echo "Opened database successfully - " . $numRows . " Accounts Found\n";
}
$ret = $db->query("SELECT id,userid,fname,lname,password,email,userrole FROM accounts ORDER BY id ASC");
while ( $rec = $ret->fetchArray() )
{
$html = " <td>{$rec[0]}</td> <td>{$rec[1]}</td> <td>{$rec[2]}</td> <td>{$rec[3]}</td> <td>{$rec[4]}</td> <td>{$rec[5]}</td> <td>{$rec[6]}</td> </tr>\n";
if ( !$rec = $ret->fetchArray() ) break;
}
$db->close();
echo $html;
?>`
So why does it not return more than one row?
In the loop you do :
// Before loop variable html contains ""
// on next line you set into $rec the next row data
// in case there is no more row you exit or not not enter the loop
while ( $rec = $ret->fetchArray() )
{
// anything that was inside $html before this assignment is replaced
// by <td>...</td> of current row
$html = " <td>{$rec[0]}</td> <td>{$rec[1]}</td> <td>{$rec[2]}</td> <td>{$rec[3]}</td> <td>{$rec[4]}</td> <td>{$rec[5]}</td> <td>{$rec[6]}</td> </tr>\n";
// here you get the next row in $rec and test if it is not null
// if it is null you exit the loop
if ( !$rec = $ret->fetchArray() ) break;
// at the end of the loop, the code in while ($rec = ...) is
// executed to get row of next data
}
$db->close();
// here you send the contents of $html to client browser
echo $html;

automatically generate tags from content in wordpress

my WordPress website contents have some words in every line,
I want a code to automatically convert every line in content to tag (every line not every word), let's say my content is like this:
Beagle puppy
Costumes
Wales
Dogs
I want tags from every line: Beagle puppy, Costumes, Wales, Dogs
I don't want to use plugins, because I used some but it needs a keyword list to match the content. I don't want to use any keyword list to match the content.
is it possible to convert every line in content into one tag?
Assuming you meant what you appeared to mean - for instance, that the source post consists solely of the lines to be converted, the lines won't include additional odd/inappropriate chracters to be handled, and so on - the following will work. If you need to convert a section of a post or some other element defined in some other way, or attach the lines as tags to the current post, etc., then you'll need to provide those details clearly.
Place shortcode [convert_post_lines_to_tags] in new output post.
Save draft, and preview (shortcode won't function yet, obviously)
Add functions to your theme functions.php
Provide "$source_post_id" where indicated.
Re-load output post
add_shortcode( 'convert_post_lines_to_tags', 'convert_post_lines_to_tags' ) ;
function convert_post_lines_to_tags() {
$source_post_id = '' ; //Provide ID Number of post with lines to be converted
$i = 0 ;
$newTags = 'New tags inserted: <br />' ;
//TIL - PHP requires double quotes to replace escaped characters
$post_content = str_replace(
array( "\r\n", "\r" ), ',', get_post( $source_post_id )->post_content
) ;
$post_line_array = explode( ',', $post_content ) ;
foreach ( $post_line_array as $line_tag ) {
$tag = wp_insert_term( $line_tag, 'post_tag' ) ;
if ( ! is_wp_error( $tag ) ) {
$i++ ;
$newTags .= $i . '. ' . get_term( $tag['term_id'] )->name . '<br />' ;
}
}
return $newTags ;
}

How to format dates in PHPExcel?

So, I'm a fairly new PHP programmer and I'm trying to set up a page that uploads a file, displays the info in a table, then writes the data to a database.
I've got these things working (I found some helpful code online) however my dates are displaying incorrectly.
For example, the date "2/15/2017 17:55" is displaying as "42781.746527778".
Here is the code:
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch (Exception $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME)
. '": ' . $e->getMessage());
}
echo '<center><table style="width:50%;" border=1>';
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 1; $row <= $highestRow; $row++) {
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL, TRUE, FALSE);
echo "<tr>";
foreach($rowData[0] as $k=>$v)
echo "<td>".$v."</td>";
echo "</tr>";
}
echo '</table></center>';
}
else{
echo '<p style="color:red;">Please upload file with xlsx extension only.</p>';
}
I get why it is displaying the date that way, however I'm not having luck in fixing it when trying to display the entire column as a date and time, or displaying it in a single cell as the correct date and time.
var_dump($objPHPExcel->getActiveSheet()->getCell('B2')->getFormattedValue());
This code displays the correct date and time for one of my sample spreadsheets, however I'm not able to get that value in the cell.
Any help would be appreciated. Thank you!
I believe this is what you are looking for? Check if the cell is a Excel date and time then extract and convert the Excel date to a PHP date.
if(PHPExcel_Shared_Date::isDateTime($k)) {
$v = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($v));
}

Wordpress get_results parsing the symbol "&"

I have a strange Thing, where I do not know where the failure is.
$name = "Fast & Furious 8";
$res1 = $wpdb->prepare(
"
SELECT
*
FROM
wp_dbtable
WHERE
filmname = '%s'
LIMIT 1
",
$name
);
$res = $wpdb->get_results( $res1 );
foreach($res as $reseachG) {
}
I have a Problem with the Symbol &. For some reasons it does not pull anything out of my table, even if it should do this.
If I use instead of the variable the text it self, like this:
$res1 = $wpdb->prepare(
"
SELECT
*
FROM
wp_dbtable
WHERE
filmname = '%s'
LIMIT 1
",
"Fast & Furious 8"
);
it works. Also, other text inside the variable works well.
So it seems that prepare, or get_results does not accept this Symbol, or changes it. How can I solve it? I couldn't find any hint on the Internet.
It might not be a PHP-Problem, or a My-SQL-Problem, it might be a Problem of WordPress classes.
Thanks a lot.
The code above is correct. The Problem was, that I pulled the text for the filmname out of the data base. He transformed the & into html-special-chars. So I had to run: htmlspecialchars_decode($filmname);. It was not easy to find, becase every print method printed the correct text.
I found an function on the Internet, which shows me hidden chars and every single real entiti. Maybe it will help some of you also:
function hexdump ($data, $htmloutput = true, $uppercase = false, $return = false){
// Init
$hexi = '';
$ascii = '';
$dump = ($htmloutput === true) ? '<pre>' : '';
$offset = 0;
$len = strlen($data);
// Upper or lower case hexadecimal
$x = ($uppercase === false) ? 'x' : 'X';
// Iterate string
for ($i = $j = 0; $i < $len; $i++)
{
// Convert to hexidecimal
$hexi .= sprintf("%02$x ", ord($data[$i]));
// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 32) {
$ascii .= ($htmloutput === true) ?
htmlentities($data[$i]) :
$data[$i];
} else {
$ascii .= '.';
}
// Add extra column spacing
if ($j === 7) {
$hexi .= ' ';
$ascii .= ' ';
}
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
$dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
// Reset vars
$hexi = $ascii = '';
$offset += 16;
$j = 0;
// Add newline
if ($i !== $len - 1) {
$dump .= "\n";
}
}
}
// Finish dump
$dump .= $htmloutput === true ?
'</pre>' :
'';
$dump .= "\n";
// Output method
if ($return === false) {
echo $dump;
} else {
return $dump;
}
}
Which shows you the hexa-codes for each char and also every single space, line, special trasformed symbol, or line-braker. It helps to see the real data.
thx to all.

Why is add_post_meta creating duplicate entries

I have a little plugin to adds a custom field with a specific format to a post. It's sort of working, but for some reason creates duplicate entries in the DB when the user clicks the "update post" button.
The part responsible for saving the meta data is here
function saveCustomLink($post){
$linkLabel = $_POST['custom-link-label'];
$linkText = $_POST['custom-link-text'];
$linkUrl = $_POST['custom-link-url'];
if($linkLabel != "" AND $linkText != ""):
$newLink = ($linkUrl != "") ? "$linkLabel: <a href='$linkUrl' title='$linkText'>$linkText</a>" : $linkLabel . ": " . $linkText ;
add_post_meta($post, "custom-meta-link", $newLink);
endif;
}
add_action('save_post', 'saveCustomLink');
There's a pastebin of the complete code here
I'm using the latest version of wordpress (3.0.5). Big thanks for any help.
Try with this:
if ($post->post_type=="post") {
if($linkLabel != "" AND $linkText != ""):
$newLink = ($linkUrl != "") ? "$linkLabel: <a href='$linkUrl' title='$linkText'>$linkText</a>" : $linkLabel . ": " . $linkText ;
add_post_meta($post, "custom-meta-link", $newLink);
endif;
}
You must check that you are working with a post (or page) and not with a revision,or an attachment (revisions are post with post_type=revision)

Resources