Author |
Message |
misterpat
Hangin' Around
![](modules/Forums/images/avatars/Animaniacs/Animaniacs_-_Stinkbomb.gif)
Joined: Mar 02, 2009
Posts: 48
|
Posted:
Sun Apr 12, 2009 8:20 pm |
|
I'm working on a custom script for my content module. I'm trying to grab the first, say 30 words, of my content articles to use as the content article's meta description.
I have it working so far, but its also grabbing the html tags. Is there a way to strip the html tags from what it gets from the database?
I tried the php strip_tags(), but cant figure out where to put it in the file to make it work.
Any ideas?
Here is the code that is working somewhat so far.
Code:<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
if (stristr(htmlentities($_SERVER['PHP_SELF']), 'meta.php')) {
Header('Location: ../index.php');
die();
}
// Get functions
global $commercial_license, $sitename, $slogan, $row, $db;
$id = $_GET['pid'];
$sql = 'SELECT text FROM nuke_pages WHERE pid=\'' . intval($id) . '\'';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
##################################################
# Include for Meta Tags generation #
##################################################
$metastring = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="._CHARSET."\">\n";
$metastring .= "<META HTTP-EQUIV=\"EXPIRES\" CONTENT=\"0\">\n";
$metastring .= "<META NAME=\"RESOURCE-TYPE\" CONTENT=\"DOCUMENT\">\n";
$metastring .= "<META NAME=\"DISTRIBUTION\" CONTENT=\"GLOBAL\">\n";
$metastring .= "<META NAME=\"AUTHOR\" CONTENT=\"$sitename\">\n";
$metastring .= "<META NAME=\"COPYRIGHT\" CONTENT=\"Copyright (c) by $sitename\">\n";
$metastring .= "<META NAME=\"KEYWORDS\" CONTENT=\"Urban Exploration Pictures\">\n";
$metastring .= "<META NAME=\"DESCRIPTION\" CONTENT=\"".$row['text']."\n";
$metastring .= "<META NAME=\"ROBOTS\" CONTENT=\"INDEX, FOLLOW\">\n";
$metastring .= "<META NAME=\"REVISIT-AFTER\" CONTENT=\"1 DAYS\">\n";
$metastring .= "<META NAME=\"RATING\" CONTENT=\"GENERAL\">\n";
echo $metastring;
?>
|
Which outputs this
Code:<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Content - Lake Hopatcong - Raven Test</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META NAME="RESOURCE-TYPE" CONTENT="DOCUMENT">
<META NAME="DISTRIBUTION" CONTENT="GLOBAL">
<META NAME="AUTHOR" CONTENT="Raven Test">
<META NAME="COPYRIGHT" CONTENT="Copyright (c) by Raven Test">
<META NAME="KEYWORDS" CONTENT="Urban Exploration Pictures">
<META NAME="DESCRIPTION" CONTENT="<div align="center"><font size="5"><span>USB Webserver is nice little Web Server package that includes Apache, MySQL, PHP, and PHPMyAdmin. Much like XAMPP, NetServer and other popular Web Servers, the application is dockable to the system tray and services can be run either portability or installed as a system service. The menu items are available in the English language via the Settings tab. This application requires roughly 22.3MB for complete portable installation.</span></font></div>
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
<META NAME="REVISIT-AFTER" CONTENT="1 DAYS">
<META NAME="RATING" CONTENT="GENERAL">
|
As you can see I need to remove those html tags.
Thanks |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
evaders99
Former Moderator in Good Standing
![](modules/Forums/images/avatars/803d73f6452557b947721.jpg)
Joined: Apr 30, 2004
Posts: 3221
|
Posted:
Sun Apr 12, 2009 8:39 pm |
|
Code:
$metastring .= "<META NAME=\"DESCRIPTION\" CONTENT=\"".strip_tags($row['text'])."\n";
|
|
_________________ - Only registered users can see links on this board! Get registered or login! -
Need help? Only registered users can see links on this board! Get registered or login! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
misterpat
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Apr 12, 2009 8:47 pm |
|
EXCELLENT! That worked. Thank you!
Now, anyone know how to cut the output down to say 25-30 words? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
evaders99
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Apr 12, 2009 8:52 pm |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
misterpat
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Apr 12, 2009 9:49 pm |
|
Ok, just tested this on a live server. I need to strip this also.
Any ideas? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
testy1
Involved
![Involved Involved](modules/Forums/images/ranks/4stars.gif)
![](modules/Forums/images/avatars/gallery/blank.gif)
Joined: Apr 06, 2008
Posts: 484
|
Posted:
Sun Apr 12, 2009 10:17 pm |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
evaders99
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Apr 12, 2009 11:38 pm |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
montego
Site Admin
![](modules/Forums/images/avatars/0c0adf824792d6d341ef4.gif)
Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Mon Apr 13, 2009 6:04 am |
|
misterpat, although the input given so far is excellent, just realize that strip_tags() is quite aggressive. It will take out more text than what you may want IF that text has "<" in it. Probably not an issue for you, but just wanted to mention it.
If you are running RavenNuke(tm), you can use the check_html() function with the 'nohtml' option and it will do a better job of the strip. So, it might instead look something like this:
$sCleanCode = html_entity_decode(check_html($row['text'], 'nohtml'));
You might want to try it with and without the html_entity_decode(). You will want to test this with many different scenarios to make sure it is doing what you want. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
testy1
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Apr 13, 2009 6:19 am |
|
never even thought of that ![Sad](modules/Forums/images/smiles/icon_sad.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
misterpat
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Apr 13, 2009 7:13 am |
|
Ok, Im going to try all of your sugestions today. Thanks for the input.
I will report back on my findings. Maybe someone else can use this code also. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
misterpat
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Apr 13, 2009 6:42 pm |
|
OK, I got something working here. Can some of You professionals look at my code and tell me if it needs cleaning up?
Code:<?php
/************************************************************************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
if (stristr(htmlentities($_SERVER['PHP_SELF']), 'meta.php')) {
Header('Location: ../index.php');
die();
}
// Get functions
global $commercial_license, $sitename, $slogan, $row, $db, $sCode, $str, $count;
$id = $_GET['pid'];
$sql = 'SELECT text FROM nuke_pages WHERE pid=\'' . intval($id) . '\'';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$count = str_replace(' ', '', $row );
$cCode = strip_tags($count[text]);
$dCode = trim($cCode);
##################################################
# Include for Meta Tags generation #
##################################################
$metastring = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="._CHARSET."\">\n";
$metastring .= "<META HTTP-EQUIV=\"EXPIRES\" CONTENT=\"0\">\n";
$metastring .= "<META NAME=\"RESOURCE-TYPE\" CONTENT=\"DOCUMENT\">\n";
$metastring .= "<META NAME=\"DISTRIBUTION\" CONTENT=\"GLOBAL\">\n";
$metastring .= "<META NAME=\"AUTHOR\" CONTENT=\"$sitename\">\n";
$metastring .= "<META NAME=\"COPYRIGHT\" CONTENT=\"Copyright (c) by $sitename\">\n";
$metastring .= "<META NAME=\"KEYWORDS\" CONTENT=\"Urban Exploration Pictures\">\n";
$metastring .= "<META NAME=\"DESCRIPTION\" CONTENT=\"".substr($dCode, 0, 135)."\">\n";
$metastring .= "<META NAME=\"ROBOTS\" CONTENT=\"INDEX, FOLLOW\">\n";
$metastring .= "<META NAME=\"REVISIT-AFTER\" CONTENT=\"1 DAYS\">\n";
$metastring .= "<META NAME=\"RATING\" CONTENT=\"GENERAL\">\n";
echo $metastring;
?>
|
Check out the nice page description it gives.
Code:<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test Content - RavenNuke Kicks Ass - Raven Test</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META NAME="RESOURCE-TYPE" CONTENT="DOCUMENT">
<META NAME="DISTRIBUTION" CONTENT="GLOBAL">
<META NAME="AUTHOR" CONTENT="Raven Test">
<META NAME="COPYRIGHT" CONTENT="Copyright (c) by Raven Test">
<META NAME="KEYWORDS" CONTENT="Urban Exploration Pictures">
<META NAME="DESCRIPTION" CONTENT="USB Webserver is nice little Web Server package that includes Apache, MySQL, PHP, and PHPMyAdmin. Much like XAMPP, NetServer and other ">
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
<META NAME="REVISIT-AFTER" CONTENT="1 DAYS">
<META NAME="RATING" CONTENT="GENERAL">
|
I notice its not giving the generator meta tags. Is that drawn from a different file? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|