PHP - Strip Tags Inside Another (allowed) Tag
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>
Similar Tutorialshi 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. In 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 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.. Hi there i was wondering how i would go about using html tags inside the php tags so i could put data from a database into a textarea / text input i had a go but had no such luck with this attempt: <?php echo "Title:<br>"; echo "<input type="text" name="title" value="$row['Title']">"; ?> the code above is to give you an idea of what i want to do, if you can point me to any guides or show me how it will be greatly appriciated Thanks, Blink359 I have a paragrpah which has tags that needs to be stripped off. so the paragraph looks like Quote <div id="ctl00_placeholderMain_pnlInTheBox" class="tabitem"> <p> HP LaserJet 9050 printer<br/> Power cord<br/> Parallel cable<br/> HP LaserJet Q8543X Smart print cartridge<br/> Printer documentation<br/> Printer software CD<br/> Control panel overlay<br/> Face-up output bin<br/> Two 500-sheet input tray<br/> 100 Sheet Multipurpose Tray<br/> HP JetDirect Fast</p> </div> I want it to look like Quote HP LaserJet 9050 printer Power cord Parallel cable HP LaserJet Q8543X Smart print cartridge Printer documentation Printer software CD Control panel overlay Face-up output bin Two 500-sheet input tray 100 Sheet Multipurpose Tray HP JetDirect Fast How would I go on about doing this.. currently i use Code: [Select] $inbox = $html->find( "#ctl00_placeholderMain_pnlInTheBox" ); if ( isset( $inbox[ 0 ] ) ) { $box =( $inbox[0] ); $box = strpos($box, ';') !== FALSE ? substr( $box, strpos( $box, ";" ) + 1 ) : $box; } else { $box = "0"; } Hi everyone! I'm trying to get the variables out of a string like this: Code: [Select] $string='this is a sentence with a load of [great, clever, textual] variables '; What I want to do is output a list of strings that have used the variables to create unique strings like this: Code: [Select] this is a sentence with a load of great variables this is a sentence with a load of clever variables this is a sentence with a load of textual variables I tried exploding the string into arrays, but what I really need to do is explode on '[' then output the words to an array (until I get to the closing ']') and then move on... The eventual string will have potentially loads of variables, but let's do one thing at a time. What's the best way of starting a project like this? Neil I am building a component where users enter a Youtube URL and press save. I need to run some code on the form field where the URL was entered to strip all but the unique identifier. i.e. something like this: $url = 'http://www.youtube.com/watch?v=_VaAlaIJ384&feature=rec-LGOUT-real_rev-rn-4r-10-HM'; strip all befor (including) 'v=' strip all after (including) '&' Can anyone suggest how I would do this? $name = "D'Angelo" ok I'm running a mysql query as $query = " INSERT INTO TEST (ID, NAME) VALUES ('NULL','$NAME')"; If the name = "D'Angelo" the apostrophe would cause it to fail. Is there a way to do this without striping the characters? Hi All I Am confused I would like to put info into a database but need it to be secure. I have some code shown below. The problem is I would like to put in ' but keep the data secure. When it comes back I do not want to show \' I think you might know what I am trying to do. Here is the code but would like to know how to stop the \' showing. Code: [Select] $password = mysql_real_escape_string(stripslashes(trim($_POST['password']))); Any help would be great thank you. Hi: Is this the proper way to remove slashes from apostrophes: Code: [Select] if ($_SERVER['REQUEST_METHOD'] == 'POST') { $myTitle = mysql_real_escape_string(stripslashes($_POST['myTitle'])); $myDesc = mysql_real_escape_string(stripslashes($_POST['myDesc'])); $myHeader = mysql_real_escape_string(stripslashes($_POST['myHeader'])); $mySubHeader = mysql_real_escape_string(stripslashes($_POST['mySubHeader'])); $myPageData = mysql_real_escape_string(stripslashes($_POST['myPageData'])); It seems to work fine, I'd just like to clarify I'm not missing anything. Thanks! I have this command that basically populates my website with titles for pages based on the information that is placed within "info.txt" I have multiple titles being created so I'd like a way of putting them in order beside alphabetically. My thought was that I could place numbers as the first character in the "info.txt" file and that would allow me to put the titles in an order I find acceptable. Now this causes the issue that I don't want those numbers displayed on my website. So the Echo needs to strip the number.... I'm lost, but my brain thinks it's a good idea. Here's the code I'm working with: Code: [Select] <tr> <td id="body"> <table id="columns" cellspacing="0"> <tr> <td> <h2>LSAV Latest Events</h2> <p>Select an event from below to view a gallery of images from that event.</p> <ul> <?php $dir = 'latest-events'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if( $file != '.' && $file != '..') { $title = file_get_contents( "$dir/$file/info.txt" ); echo "<li><a href=\"event-viewer.php?event=$file\">$title</a></li>"; } } closedir($handle); Hey folks, I am trying to create a small script that will retrieve content from a site, strip it of everything but human readable words, then remove numbers, single letters, and words that I specify. I have the following code which is live on http://salesleadhq.com/tools/crawler/meta.php?url=http://www.cooking.com. My problem is that it is not removing all of the the words I specify, only some... ?? I think i would rather an external word list as well... if anyone can assist me with that. Thank you! Code: [Select] <?php $url = (isset($_GET['url']) ?$_GET['url'] : 0); $str = file_get_contents($url); ####################################################################3 function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } #--------------------------------------Strip html tag---------------------------------------------------- function StripHtmlTags( $text ) { // PHP's strip_tags() function will remove tags, but it // doesn't remove scripts, styles, and other unwanted // invisible text between tags. Also, as a prelude to // tokenizing the text, we need to insure that when // block-level tags (such as <p> or <div>) are removed, // neighboring words aren't joined. $text = preg_replace( array( // Remove invisible content '@<head[^>]*?>.*?</head>@siu', '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu', '@<object[^>]*?.*?</object>@siu', '@<embed[^>]*?.*?</embed>@siu', '@<applet[^>]*?.*?</applet>@siu', '@<noframes[^>]*?.*?</noframes>@siu', '@<noscript[^>]*?.*?</noscript>@siu', '@<noembed[^>]*?.*?</noembed>@siu', // Add line breaks before & after blocks '@<((br)|(hr))@iu', '@</?((address)|(blockquote)|(center)|(del))@iu', '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu', '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu', '@</?((table)|(th)|(td)|(caption))@iu', '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu', '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu', '@</?((frameset)|(frame)|(iframe))@iu', ), array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",),$text ); // Remove all remaining tags and comments and return. return strtolower( $text ); } function RemoveComments( & $string ) { $string = preg_replace("%(#|;|(//)).*%","",$string); $string = preg_replace("%/\*(?:(?!\*/).)*\*/%s","",$string); // google for negative lookahead return $string; } $html = StripHtmlTags($str); ###Remove number in html################ $html = preg_replace("/[0-9]/", " ", $html); #replace by ' ' $html = str_replace(" ", " ", $html); ######remove any words################ $remove_word = array("amp","carry","serious","for","re","looking","accessories","you","used","wright","none","selection","come","second","you","new","a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"); foreach($remove_word as $word) { $html = preg_replace("/\s". $word ."\s/", " ", $html); } ######remove space $html = preg_replace ('/<[^>]*>/', '', $html); $html = preg_replace('/\s\s+/', ', ', $html); $html = preg_replace('/[\s\W]+/',', ',$html); // Strip off spaces and non-alpha-numeric #remove white space, Keep : . ( ) : & //$html = preg_replace('/\s+/', ', ', $html); ###process######################################################################### $array_loop = explode(",", $html); $array_loop1 = $array_loop; $arr_tem = array(); foreach($array_loop as $key=>$val) { if(in_array($val, $array_loop1)) { if(!$arr_tem[$val]) $arr_tem[$val] = 0; $arr_tem[$val] += 1; if ( ($k = array_search($val, $array_loop1) ) !== false ) unset($array_loop1[$k]); } } arsort($arr_tem); ###echo top 20 words############################################################ echo "<h3>Top 20 words used most</h3>"; $i = 1; foreach($arr_tem as $key=>$val) { if($i<=20) { echo $i.": ".$key." (".$val." words)<br />"; $i++; }else break; } echo "<hr />"; ###print array##################################################################### echo (implode(", ", array_keys($arr_tem))); ?> This is going to sound like a very beginner question, because it is. I am modifying some free code snippets to fit my use and stuck. It's probably a simple fix. First here is the code. This is printing from a while loop. <?php print("[". $current_month .",". number_format($remaining_balance, "2", ".", ",") . "],");?> Here is the last remaining items from the loop at it comes to an end: [343,14,495.86], [344,13,682.26], [345,12,863.91], [346,12,040.79], [347,11,212.87], [348,10,380.12], [349,9,542.52], [350,8,700.02], [351,7,852.61], [352,7,000.26], [353,6,142.94], [354,5,280.62], [355,4,413.26], [356,3,540.85], [357,2,663.34], [358,1,780.72], [359,892.95], [360,0.00], My question is kind of simple, how do I get it do the comma doesn't print on the last print? I need it to end like this: [359,892.95], [360,0.00] Does that make sense? I don't know if I explained it well. I could really use some help! Thanks so much! Firstly I'm sure the answer is simple however due to my inexperience I am unable to figure it out!
I am executing a simple query to retrieve all ISBN numbers within my db and display these in a table.
In my db some of the ISBN numbers contain hyphens and some don't. I would like to display then in my table without hyphens.
I'm grateful of any assistance and advice.
I know I can remove all the hyphens from the db by executing a separate query however I'd like to strip them if possibly.
My Code;
$query = "SELECT * FROM book WHERE status != 'Archive' ORDER BY id"; while($row = mysqli_fetch_array($query)){ ?> <tr> <td><a href="itemView.php<?php echo '?isbn='.$row['isbn']; ?>" </a></td> <td>...</td> <td>...</td> <td>...</td> <td>...</td> </tr> <?php } ?>J Looking for the best method to conditionally strip leading zeros for the following situation: $a = array(01, 02, 03, ... 10, 11); $a < 10 ? $a = ? : ''; For the following result: 1, 2, 3, ... 10, 11 Is there a better method than explode? Hi All,
How could i implemnent tab strip (jquery ui tab) in php.
Any help in this regard will be appreciated
Thanks
Ahsan
Hey guys. I am trying to strip everything between a key phrase and ending tag but for some reason it is not working. I always get blank data. I've tried many different ways but no luck.
basically I have a script that connect to imap and store emails into MySQL as service tickets. works great but I am trying to strip everything except for user reply because currently if a user reply to an email it re-inserts the entire email into MySQL. I added a key phrase at the top of all outgoing emails .
1. structure looks like this.
--Reply below this line to respond--
------------------------------------------------------------------------------------------------
Email body message...
2. When replying to the message it becomes
New Message reply......
--Reply below this line to respond--
old message body.
3. so I would only like to insert the new reply message only.
This is what I got so far.
$message=strip_tags($message, "<br><div><p><u><hr></section>");
$message=preg_replace("</p>", "br /", $message); $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message); $message=clean("<br/><hr><u>Received On $rep_date / $from_email</u><br><br/>$message"); it inserts the "Received On date and From but $message is blank. If i remove $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message); it inserts the entire email Any suggestion on what i am doing wrong? thank you all very much. Hey there. Thinking this should be an easy one but I can only seem to find info on the string replace function. What I'm trying to do is strip everything after the @ from an email variable. So for example $mail variable comes in as me@gmail.com How would I strip the variable to only contain me and remove the @gmail.com I'll keep searching for the answer myself but if anyone can throw me a bone it's be appreciated. Cheers I'm trying to make a script that will search the source code of a given url and strip every email address that pops up. I already have a script that will crawl around, jumping from webpage to webpage... i just need to figure out how to strip the contents... any suggestions? |