PHP - Strip Only Certain Tags, Remove Body Tags, But Keep Its Content.
hi everyone,
did not know what to make the subject, but here is what I want to do: I have a string, which gets returned to me from a linux app on my server, it looks something like this: Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8"> <TITLE> </TITLE> <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.2 (Linux)"> <META NAME="AUTHOR" CONTENT="Administrator"> <META NAME="CREATED" CONTENT="20110106;14170000"> <META NAME="CHANGEDBY" CONTENT="HOD"> <META NAME="CHANGED" CONTENT="20110522;16540000"> <STYLE TYPE="text/css"> <!-- @page { margin: 0.26in } P { margin-bottom: 0.15in; direction: ltr; color: #000000; line-height: 0.15in; text-align: justify; widows: 2; orphans: 2 } P.western { font-family: "Arial", sans-serif; font-size: 10pt; so-language: en-US } P.cjk { font-family: "Batang", "바탕", serif; font-size: 10pt } P.ctl { font-family: "Times New Roman", serif; font-size: 10pt; so-language: ar-SA } A:link { color: #0000ff } --> </STYLE> </HEAD> <BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" DIR="LTR" STYLE="border: 5.05pt double #000000; padding: 0.67in 0.92in"> <P>I want this and the tags around it, just not the html, head, body and their closing tags.</P> </BODY> </HTML> within the body, the tags are each styled for example: <p style="color: red"></p> so I cannot just get rid of all html, I want to get only all the content within the body tags, but without the body tags obviously strip_tags does not work as i need, I only want to strip certain tags. If someone can help me with this i will much appreciate it. Similar TutorialsIn Wordpress, the hyperlinked tags are displayed by <?php the_tags(); ?> I want to de-link the tags to show simple text (instead of link). I tried Code: [Select] ereg_replace to replace hyperlink elements; strip_tags, but none of them worked. I need to strip some html tags out of an uploaded string of code. I need to keep the <td> tags...but some code that is being uploaded include <p> tags INSIDE the <td> tag.
How would I go about stripping ALL other tags inside these allowed tags: <td> <tr><table>
I have been searching on google for a while, but i couldn't find it. So i thought may be you could direct me to some tutorial or steps if you knew. Basically, i am working on a articles directory and the big text area where the main article will be entered, i want to allow all the links (link tag) on it but not any other html tags. Currently i am using strip tags and so its cutting down the tags and all the links are being displayed naked on it. So can you please tell me how do i do it? Thanks.. Hello all, I'm trying to generate a regex that will remove UTM parameters from my refferrer URLs. Code: [Select] <?php //"test" parameter is lost echo preg_replace("/&?utm_(.*)\=[^&]+/","","?utm_source=bottom&utm_medium=widget&test&test&utm_campaign=testcamp"); ?> The regex works on removing the paremeters whilst keeping parameters before and after in tact. However parameters in-between are lost. Any ideas would be great. I'm testing the above code on http://writecodeonline.com/php/ This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326002.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=347065.0 Hi guys I need to be able to extract (into an array) the content between two tags "<!--" and "-->" in a string ($string). I have $string = "<!--HELLO WORLD-->"; $tags = "/<!--(.*?)--!>/"; preg_match($tags, $string, $matches); return $matches[1]; but it does not seem to work, (no error code, nothing). Any help much appreciated, I am asking out of curiosity, how does this problem usually get solved, when using a tag system to sort content, and users enter similar tags. For example: flower and flowers... which means the difference between singular and plural. Judging by other sites which are around, this problem is not solved at all, they simply let you add as many tags as you want and then rank the most used tags, it indeed is a solution, but seems more like a walk-around solution to me. Any ideas how somebody could approach to solve this one? EDIT: My suggestion would be an analysis function, which analyzes the entered tag and then suggests the user that similar tags have been already entered and perhaps he wants to choose one of those which have been already entered. This does work though with a high traffic websites what can happen is the following: php and php5 You can end up with two similar tags which are both widely used though have different meanings to the user base. This one could be solved by simply prohibiting similar tags with little additions or changes, and so to speak "forcing" the user to choose something which is already there. May be a way, though it can turn out as a bad solution as well. Do anyone know how i can put the html tags in the same line as the other html tags? Here's an example: Code: [Select] Images | Link | Delete | Enabled On my code, it break the tags to the new line without put on the same line as the other tags. Here's the code: Code: [Select] [code]<?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); if($username == '') { $errmsg_arr[] = 'username ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, public FROM members WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?id='.$row['id'].'">Delete</a> </td> | <p> <p id="test">'.$row['Public'].'</td>''; } } } ?>[/code] Say I have the following text stored in a MySQL database... Code: [Select] <b>Classic Quote from movie</b> and I retrieve it into a variable called $text, how do I properly echo that so that it keeps the bold tags and actually display the text "Classic quote from movie" in BOLD? I'm doing something wrong somewhere along the line (simply doing "echo $text;") because it displays on the page as... Code: [Select] <b>Classic Quote from movie</b> Instead of... Classic Quote from movie Any info on properly storing and echoing back HTML would be very appreciated. I found this code on a website: <?php //Reads ID3v1 from a MP3 file and displays it $mp3 = "1.mp3"; //MP3 file to be read //make a array of genres $genre_arr = array("Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge", "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B", "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska", "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient", "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical", "Instrumental","Acid","House","Game","Sound Clip","Gospel", "Noise","AlternRock","Bass","Soul","Punk","Space","Meditative", "Instrumental Pop","Instrumental Rock","Ethnic","Gothic", "Darkwave","Techno-Industrial","Electronic","Pop-Folk", "Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta", "Top 40","Christian Rap","Pop/Funk","Jungle","Native American", "Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer", "Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro", "Musical","Rock & Roll","Hard Rock","Folk","Folk-Rock", "National Folk","Swing","Fast Fusion","Bebob","Latin","Revival", "Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock", "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band", "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson", "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus", "Porn Groove","Satire","Slow Jam","Club","Tango","Samba", "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle", "Duet","Punk Rock","Drum Solo","Acapella","Euro-House","Dance Hall"); $filesize = filesize($mp3); $file = fopen("1.mp3", "r"); fseek($file, -128, SEEK_END); $tag = fread($file, 3); if($tag == "TAG") { $data["song"] = trim(fread($file, 30)); $data["artist"] = trim(fread($file, 30)); $data["album"] = trim(fread($file, 30)); $data["year"] = trim(fread($file, 4)); $data["comment"] = trim(fread($file, 30)); $data["genre"] = $genre_arr[ord(trim(fread($file, 1)))]; } else die("MP3 file does not have any ID3 tag!"); fclose($file); while(list($key, $value) = each($data)) { print("$key: $value<br>\r\n"); } ?> How would i edit this to look in a directory, and sub-directories and get information for every mp3 and add the data to a mysql database (the latter i can do easily) Hi guys, i have not started this as of yet, however i will be given a project to make a micro-blogging website similar to that of Twitter or Facebook but obviously on a much smaller scale I have been searching on google however i have not found anything. Maybe i haven't been using the right words in my query, not sure :-/ I have been trying to do some research, however i can't seem to find how to incorporate @ tags found in Twitter / Facebook. e.g. If i want to tag a person in a Status Update: Hey @John Smith, Football in the park at 3pm? If anyone is able to help i would be grateful Thank You alright I've seen and use Code: [Select] <?php Code: [Select] <?but never before do I recall seeing Code: [Select] <?= Nor do I even know where to look that up, so.. anyone ever see that used before, if so, any insight as to why someone would choose that? How does PHP continuity exist in different php tags? for example, if i connect to a database in a header, and close the tag, can I still work off of the same database in another tag? Hello i said to replace the short php tags (<??>) with long php tags (<?php ?>) but it is giving me Parse errors -.- the parse error apears if i have <?php//NOTE ?> With <?//NOTE?> Is all ok and it dosnt give me that error .. could anyone please tell me why dos it give the error and some more details about the tags etc Thanks in advance I have just been given some code that is live on a web site. I pulled it down to my local linux machine and the php will not run. I have worked out the issue the php tags are <? scripting ?> it is missing the php. I have a couple of questions how do I get my local linux machine get <? scripting ?> this to work and I have a lot of code that is like this and I am sure that it is no longer secure is this right? I am working on a poject, where the search functions doesnt work as the user wishes. The coding is technically correct, but the idea behind it is wrong. Basically at the moment, the script receives this: thesite.com/search.php?q=xxxx&Submit=Search The search script then runs a database query to search the tag coloumn, looking for like $q. This would work, however the structure of the coloumn is tag1, tag2, tag3, tag4. So my resolutions is this so far: I explode the $q variable, via the + (if you search more than one term "thesite.com/search.php?q=search+stuff&Submit=Search" I then count the elements in the array and write the database function accordingly Code: [Select] $var = @$_GET['q'] ; $trimmed = trim($var); $searchpieces = explode("+", $trimmed); $dbquery=""; $count = count($searchpieces); for ($i = 0; $i < $count; $i++) { if($i == 0){$dbquery.="tags = $searchpieces[$i]";} elseif($i > 0){$dbquery.=" OR tags = $searchpieces[$i]";} } So my database query is $sql = "select * from gallery where $dbquery order by date DESC " . $limit; so my question is this.. how to i eplode the tags database coloumn, so my datase query an look at each tag fro "tag1, tag2, tag3" as "tag1" "tag2" "tag3" I am not even sure if this is possible, but its the system that is already in place. The problem with the current system, is because the pictures have alot of tags and the database query is $like $q, it just shows all images in the database as the result I wish to have all my products show in an XML for googles product search. Also when I try to view this in internet explorer I get an error about quote marks (") being invalid. Code: [Select] <? header('Content-Type: text/xml; charset=UTF-8'); include("includes/functions.php"); $connected = dbConnect(); // the DATE_FORMAT is to make the date RFCwhatsit compliant $datetocheck = date("Y-m-d H:i:s"); $sql = "SELECT * FROM `products` ORDER BY `productTitle` ASC"; $resultset = mysql_query($sql); //echo("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ? >\n"); echo("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <? echo('<atom:link href="http://www.site.com/rss.php" rel="self" type="application/rss+xml" />'); ?> <channel> <ttl>1</ttl> <title>Welcome - RSS Feed</title> <link>http://www.site.com?s=rssimg</link> <description>RSS Feed</description> <language>en-us</language> <pubdate><?=gmdate("D, d M Y H:i:s \G\M\T");?></pubdate> <lastbuilddate><?=date("D, d M Y H:i:s \G\M\T");?></lastbuilddate> <generator>OnTheFly</generator> <image> <title>Welcome - RSS Feed</title> <url>http://www.site.com/images/header.png</url> <link>http://www.site.com?s=rssimg</link> <width>88</width> <height>31</height> </image> <?php while ($result = @mysql_fetch_assoc($resultset)) { $submitteddatetime = date("D, d M Y H:i:s \G\M\T", strtotime($datetocheck)); ?> <item> <title><![CDATA[<? echo(htmlentities(stripslashes($result[productTitle]))); ?>]]></title> <guid>http://www.site.com<? echo("/?v=" . $result[Pid] . "&h=r"); ?></guid> <pubdate><? echo($submitteddatetime); ?></pubdate> </item> <?php } ?> </channel> </rss> Hi Guys Whats the easiest way to store tags in a database from a php form? If I have a text field called tags, and each tag is comma seperated how do I process the data? I have a table called tags, with 3 fields, tag_id, post_id and tag Basically how would I basically turn this input: a tag, b tag, c tag from a form field to tag_id cat_id tag 1 dont worry about me, i can work this out! tag a 2 dont worry about me, i can work this out! tag b 3 dont worry about me, i can work this out! tag c Many Thanks HI,
I'm using;
https://github.com/o.../PHP-Pagination
It works on my local test server, but on EC2, short tags are apparently not enabled by default.
The pagination is printing php:
<div class="pagination"><ul class="<?php= implode(' ', $classes) ?>"> <li class="<?php= implode(' ', $classes) ?>"><a href="<?php= ($href) ?>"><?php= ($previous) ?></a></li> <li class="number active"><a data-pagenumber="<?php= ($current) ?>" href="#"><?php= ($current) ?></a></li> <li class="number"><a data-pagenumber="<?php= ($current + $x + 1) ?>" href="<?php= ($href) ?>"><?php= ($current + $x + 1) ?></a></li> <li class="number"><a data-pagenumber="<?php= ($current + $x + 1) ?>" href="<?php= ($href) ?>"><?php= ($current + $x + 1) ?></a></li> <li class="<?php= implode(' ', $classes) ?>"><a href="<?php= ($href) ?>"><?php= ($next) ?></a></li>I tried replacing <? with <?php to no avail. Not sure if the fact that one dependency is named "render.inc.php" instead of just ".php" which is causing the issue. Any ideas why apache is doing this? I'd rather not edit the .ini. Thanks.. Edited by arbitrageur, 03 November 2014 - 01:00 AM. |