Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To List/find Html Tags In Text


What I try to do is to search a text for html tags.

Why. Because I want to use nl2br on the text, but since this command add
br instead of all /n it is not a nice thing to add t.x. a html list inside
the text. Of course it is possible to add the list and remove all space
between li tags, but this is not so readable to the writer.

What I try to do is also to add nl only in the plain text and inside li
and td tags. So in the li case I have to find <ul> and </ul> and <table>..




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Strpos To Find Xml Tags To Pull Out The Text Data
I'm trying to use strpos to find these xml tags so I can pull out the text data; but the bracket chars won't let the function work. Is there another way to do this?

$php_XML_tag = "<codeFacility>ZNY</codeFacility>";
$pos = strpos($php_XML_tag, '<codeFacility>');
print $pos;

results is $pos == 0

Text Data Containing HTML Tags?
I am working on a content system. But cannot seem to figure out how to display text that has html formatting tags included. I use a form and the TEXTAREA to have users submit text. I save it to a MySQL db.

I want the user to be able to use html tags such as <B></B>, but when I display what was saved, the HTML tags do not function. I have read about addslashes(), and removeslashes(), but am not sure I fully understand them. Should I be trying these?

Function To Add HTML Tags To Text
i have 4 fields (noun1, noun2, noun3, verb1) for a person to fill out and what they put into these fields will be printed out at certain points throughout a quotation (basically, it's a madlib with quotes from the simpsons and futurama).  after the four fields, i allow them to select from a drop-down select menu with the options of bold, underlined, italics. 

what i need done is that IF they select any of those, i need what is printed out from the fields to be printed out with HTML tag formats ().

Detecting URL's And Html Tags In Text, Input From Form
Is it possible to check text and set a PHP variable if someone inputs links, <h1></h1> ect. and other html tags when filling out your form mail or guestbooks?

How To Find Characters In Between Two Tags
I was wondering what would be the most simple way to find the text thats between to predefined tags in a string, and then set that text to a variable. Example...

I want the text inbetween these tags [set]iwantthistobeavariable[/set] to be set as a variable.

HTML Email Using PHP Problem (Receive Html Tags)
When I send the html email, the only thing I receive is the tags (the
html codes basically). I want to be able to see the email like a html
page, what is wrong with my code? Here is a copy paste of it.

$HTML = "</html><body><img src='http://www.somewebsite.com/
someimage.jpg'></body></html>";

$headers = "From: $from
";
$headers .= "MIME-Version: 1.0
";
$boundary = uniqid("HTMLDEMO");
// Now we attach the HTML version

$headers .= "--$boundary
".
"Content-Type: text/html; charset=ISO-8859-1
".
"Content-Transfer-Encoding: base64

";

$headers .= chunk_split(base64_encode($HTML));

mail($to,$subject,"",$headers);

print "mail Sent<br>";

The email I receive has this as text:

</html><body><img src='http://www.somewebsite.com/someimage.jpg'></
body></html>

Parsing Text - Capture Text Between Two Tags
I want to have text in files, such as

{body}
{/body}

and then be able to open that file and grab all of the data inbetween those tags. I could open the file and go through it until I see the {body} tag and then store data until I reach {/body} but that is a bad way to do it.

Find A List Of The Mysql Query Syntax?
Where would I find a list of the mysql query syntax?

Help Inserting <p> Tags Into Text
I am having trouble writing this in PHP and was wondering if anyone could help me.

On my website I have a basic system where I can type HTML code into a box and it appears on a webpage. As simple as that.

The problem is that a lot of the items I am putting into the site are Text based. They are separated into paragraphs by double returns (though the line in-between may have white space on it like spaces). It is very slow to put all the paragraph tags in.

What I would like to be able to do is to be able to use html tags like li, ol, table, tr, td th, a, b, c, h1 etc without having to put the paragraph tags in. I then would like php to place paragraph tags around the paragraphs and place a br where there is only one return (but only do this outside the previously mentioned tags).

Reg Exp For HTML Tags
I'm have trouble with my regular expressions trying to grab the contents of html tags. Lets say i'm tyring to get what is between all my <td> tags. I wish to put all matches in an arry but its just not working for me. Well, I'm sure its working fine, i'm just not doing it right. I was trying this PHP Code:

HTML Tags...
Say if I wanted to allow people to use <strong> <em> <a href etc. when posting a comment on my story would PHP know that it's HTML and parse it or would I need to tell it somehow that there may be HTML coming in from the form before it stores it in the database? And when I query the database do I need to let it know it might be returning some raw HTML?

Extracting Text Between Tags Is Tricky!
Problem:
I want to get the whole text between the opening tag <%OPTIONAL%>
and the closing tag <%/OPTIONAL%>.
The right block is found by (and contains) the placeholder
{#xmreisepop_reisepreistext_1_3#}.

<%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags
again.

My first idea was:
<%OPTIONAL%>(.*?){#xmreisepop_reisepreistext_1_3#}(.*?)<%/OPTIONAL%>

But this does not work with the following peace of text, because it takes
the first <%OPTIONAL%> before and the first
<%/OPTIONAL%> after the placeholder.

<%OPTIONAL%>
....bla bla bla....
<%/OPTIONAL%>
....
<%OPTIONAL%>
....
{#xmreisepop_reisepreistext_1_3#}
....
<%/OPTIONAL%>


Then I tried it with this version:

<%OPTIONAL%>(.*)(?!(<%OPTIONAL%>|<%/OPTIONAL%>)){#xmreisepop_reisepreistext_1_3#}(.*?)<%/OPTIONAL%>

No success!

Stripping HTML Tags
I have the following code at the beginning of a php page:

Checking HTML Tags
I'd like a system whereby certain HTML tags can be used but others can't. And the nice strip_tags function dealt with that rather nicely.

The problem is checking for tags left open. I've tried various things with regular expressions and found ways to detect when a tag is left open, but not how to do anything about it. Ideally, I'd like something that would remove any opening tags if there is already a tag of that sort open and add a closing tag at the end of the message if a tag isn't closed.

Cleaning Html Tags
somebody knows any way to put off all html tags from a file. I want to store cleaning pages for information purposes.

Php Mail With HTML Tags
I have written a php code to send the mail,Iam able to receive the mail but the mail is coming with all html Tags included like Code:

How Can I Replace All HTML Tags?
How can i replace all HTML Tags?

Best Way To Display HTML Tags?
I am trying to display the source of HTML files withing pages on my site. What is the best way to display the code so that it doesen't get parsed as HTML?

Problem With Html Tags
I need html tags in my forum pages to show up, but not to be active.
I have tried to change the tags to html equivalent code using php, but
still they are active.

How do I go about chaning them to non-active?

Get Data Between HTML Tags
I'm looking to get the baseball score between the html tags on yahoo and
create my own rows with just the data.

So far I have this code
-----------------------------------------------------------
$data = file_get_contents('http://sports.yahoo.com/');
list(, $data_split) = explode('<td width="50%" class="yspscores">', $data,
2);
list($data2, ) = explode('</a></td>', $data_split, 2);
$data2 = strip_tags($data2);
echo $data2;
-------------------------------------------------------

It gives me all the results but I want to do a loop that will find the first
row of scores create a new row and put the data in the new row then find the
next row of scores create another new row and insert the data and continue
that pattern to the end.



Removing HTML Tags
I am using ajax, so I am manipulate the text with either php(prefer) or javascript.
I have a text area where the user enters whatever. They click send and a 'js' function gets called and it calls my sendRequest function and sends over the data to my php file to be insert into my db.

What I want to do is remove any of the html/js tags I can. The only thing I want to keep is the spacing the user enters (line spacing).

My php file - I have tried many different ways, but none of them seem to work

$txt = $_GET['text'];

$stuff = array("","");
$txt = str_replace($stuff, "<br />");
echo strip_tags($txt, '<br />');

So using the code above if I enter:
<b>Test</b>

This is a test

The Results is:
TestThis is a test

I've tried another method using 'preg_match', but i am getting an error b/c of the function.

Htmlentities Except For Certain Html Tags
I have a script that retrieves a database record that's created by a user.  In that database record are bbcodes like [p].  My problem is that the records are for tutorials, so I need it to display the HTML as raw text, therefore I have to use htmlentities and even though I use str_replace to replace the bb tags, it still displays the <p> tags(previously [p]) as html.

I need the <p> tags to be translated into html so my layout works correctly.  Is there anyway to do this? Code:

Restricting Certain HTML Tags
I want to restrict users to only using certain html tags, such as a, b, i, and u, and for certain special purposes only embed.

Remove HTML Tags?
Basically what I am doing is making a blog of mine on my website AJAXable (and I copyright that word!). So I have it when I'm logged in all the script is enabled and I can edit the blog. Now when I click on the text it generates all the info in a textarea. However! I see my html tags. Now I'm pretty sure once I click on the submit button, it is going to store all those tags into the database. I do not want that ^_^

Is there a way with PHP or maybe Javascript to go through and delete these tags?

Highlighting Search Text, But Not Inside Tags
I've looked at some examples of text highlighting in this forum, and they all work fairly well. But I have a problem with my html tags. I have a site where the main body text is kept in a database text field. This text can contain some simple html. In particular urls. These urls get completely messed up with the css-tags that i insert to highlight the search words. Is there a simple regex expression that can make my script skip anything between < and >?

I am currently using the example from this thread:

Removing Attributes From Html Tags
I want to build a class which will return a stripped version of variable containing HTML tags.

In my constructor i will use strip_tags to get rid of the unwanted tags in the variable.

After that i'll call a method cleanup() which has to do the hard work.

Lets say i fill an array with values containing attributes like Onclick Onmouseover Style in my constuctor.

I will allow de <a> tag to be used, but i want to strip the tag from attributes mentioned above.

Removing Empty HTML Tags
Long story short:

Converting word files to readable HTML (approx 1200 docs).

Got it going good, have one problem left:
Due to the difference between hard and soft carriage returns, sometimes end up with <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p> and I need to get rid of these. There are differring numbers of non-printing characters and spaces between the p tags.

I am convinced that a regular expression will do this but so far have not found one.

So basically what I need is to remove any paragraphs that contain no printable characters.

Strip Html Tags ATTRIBUTES With Reg Exp
I want to strip html attribute within a tag. e.g.:

<td class="blah" colspan="2" bgcolor="#ffffff">blah</td>

And I want to leave the 'colspan="2"' intact. result after stripping with reg exp:

<td colspan="2">blah</td>

Textarea - HTML Tags Problem
The following is my php code for a form to subit data from a textbox


echo"<td colspan="3" valign="top"><textarea wrap="virtual" cols="50" rows="8" name="addr" >Type address here.</textarea></td>";

But, when the data submitted to my database, it included all the html tag such as <div>, &nbsp;...so how to I just submit plain text to my database?

Extracting Specified HTML Tags With Regex
I have a regex problem, spent about 7 hours on this now, but I don't find
the answer in the manual and googling, though I think this must have been
discussed before.

I try to simply extract the title and meta tags of a valid HTML page as an
array:

function extract_html($filename)
{
$ret = array();
// put file into string
$contents = file_get_contents($filename);
// title
$p = preg_match_all('<(title|TITLE)>(.+)</(title|TITLE)>', $contents,
$matches);
if ($p > 0) {
$ret[] = $matches[0][0];
}
// metatags
$p = preg_match_all("<(meta|META)(.+)>", $contents, $matches);
if ($p > 0) {
for ($i=0; $i<$p; $i++) {
$ret[] = $matches[0][$i];
}
}
return $ret;
}

What happens is:
- The title part gets no match
- The meta matches are correct, but miss the opening <

The examples I have seen in the manual all seem to have no problem with <
and > in the patterns. I don't know where to look and also don't understand
all parts of the regex section.

Preg_replace Words Only - Not In Html-tags
I'm having a hard time replacing words "only", that is, do not replace occurences of the word in an HTML-tag. Here's some code: PHP Code:

RegX To Grab Everything Outside HTML Tags
i have some 350 $terms in the dictionary to check against the $rf. PHP Code:

Eregi (html Anchor Tags)
I need to get all the html anchor tags from a string. heres my eregi line: PHP Code:

Replacing Bbcode With Html Tags Using Php
i have a place for people to post with bbcode (written with javascript), the data is posted and sent to a mysql database, and retrieved from my website's page, where it is displayed.

when the data shows up on the page, the bbcode is still visible. is there a php script for this? if there is where would i put it? on the website's page?

How To Find A Match In A Text Field ?
i am using ereg($rowvalue[0],'humor2')==true to find a match in the text field. how can i find a exact match, ie. the text field contains 'humor,humor2'

so, if using ereg the result will be true for both humor and humor2 but only 1 - humor2 is correct. how do i find an exact match ?

Remove Some HTML Tags When Post A Form
A user writes an article using WYSIWYG HTML based editor and submit it to script.php(<form method="post" action="script.php">). I only want to keep the HTML tags which are in my allowance list and remove other tags from the post string. For example, here is the allowance list of tags:

<b>,<strong>,<p>, <ul>,<ol>,<li>, <a>

Before submission:

Regular Expression Strip HTML Tags
I'm stripping out the attributes in <TD> tags...but I want to strip out
everything BUT the COLSPAN attribute.

The following strips out all attributes. What do I do if I want to keep a
certain one?

eregi_replace("<TD[^>]*>","<TD>", $string);

Stripping HTML Tags With Regular Expressions
So I need a regular expression to strip out all HTML tags EXCEPT the ones I've allowed.
I think I almost have it, but I can't get the negation right..

"/</?(^IMG|A|FONT|B|I|U|STRONG|EM|CODE|PRE|H1|H2|H3|H4|H5|H6)(.*)>?/i"

Now the ^ isn't negating because it's not in a class. So how would I negate all those tags (meaning match anything EXCEPT those?) Also, what's a better alternative to the .* match so that they can't just throw a newline in there and **** things up?

Replacing Breaks In Variables With Html Tags
I was wondering if anyone here knows how to replace breaks in variable data with html tags like <BR> e.g.( I have a music site and when i insert information through web forms that input data into my mysql database like tour dates for instance:

04/05/2001-County Coliseum, Richmond, VA
04/06/2001-MCI Center, Washington DC

i would like to replace breaks in the data with <BR> tags before it is sent to the database like this:

04/05/2001-County Coliseum, Richmond, VA<BR>
04/06/2001-MCI Center, Washington DC<BR>

does anyone have any ideas?

Regular Expression To Remove Html Tags
from the database. Im displaying the intro for an article from the body of the article and I need to omit any html tags included in the beginning of the article..

$intro = ereg_replace("[<*>]", "", $intro);

How To Replace Special HTML Tags With Attributes
I'm working with XML and sometimes it's necessary to use temporary tags, that should be replaced before showing the source. How can I delete these tags?

I assume, that I require preg_replace, but I don't know how to do it. Let's say I want to replace the <iteration ... > and the </iteration> tag from the following HTML code:
PHP Code:

How To Strip Styles Embedded Within Html Tags?
I'm a complete PHP n00b slowly finding my way around
I'm using the following function that I found on php.net to strip
out html and return only the text. It works well except for when
you find styles embedded within the tags
eg: <h3 id="pageName">Have a great day!! </h3>
This throws an error, whereas
<h3 >Thank you for your purchase! </h3works like a charm.
It also falls over when crappy code has <h3>&nbsp;</h3between
the tags.

What do I need to add to the below function to get it to work on
cases like above?

The function is:

function html2txt($txt){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out
javascript
'@<[/!]*?[^<>]*?>@si', // Strip out
HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style
tags properly
'@<![sS]*?--[

]*>@', // Strip
multi-line comments including CDATA
"@</?[^>]*>*@"

);
$text = preg_replace($search, '', $txt);
return $text;
}

Find And Replace Text In Preg_match Array
I'm trying to change a font color html code once my preg_match_all reads the file. Now the code only shows up when a winner has been posted for that tour. Otherwise it's not visible. So I want to search the preg results which is $matches, for the "font color=3FFF5E" and replace it with "font color=FFFFFF". If the code is not found, continue what it was doing. Code:

Find URL And Replace With HTML Hyperlink
I have a database full of user input, some users enter in URLs.. when I display this information, I would like to go through the text, look for URLs and turn those into real hyperlinks... so I need to take http://www.whatever.com and make it a real hyperlink.

Am I in the right place? If so, how would I go about doing this?

I am using php/mysql and I would like to simply wrap a function around, for instance, my $output variable which holds the data retrieved from a user input.

Strip HTML Tags, And Save To A Seperate Array
I am trying to take a string, and seperate the HTML code from the string and put it into an array, and then take my string it into several strings of around 110 characters, and then put the HTML back in, does anyone think it can be done, and how?

Outlook Chopping Href Tags In Html Mail
I have been trying to send a multipart text and html message through the mail() funciton. It works beautifully with Hotmail. However, when it is received by the IceWarp web-based mail server or by Outlook, some of the HTML is hacked out. Specifically, on href tags, look like this when viewing the source: <a href=ttp://.... It also chops off the last character of the url and the quote before the end ">" on the tag. I can't figure out what is happening ....

IIS Could Not Find .php File, However It Finds Html Files In The Same Dir
IIS could not find .php file, however it finds html files in the same
dir.....

http://localhost/test => the default.htm will be hit, no error

http://localhost/test/test.php => 404 error not found( it exists in the
dir)

The security is set ok, something wrong with the php runtime??
Strange because my application on localhost/prog works smooth.........

Echo A String, Including Html Tags/'unescaped' Php Characters
Is there a way in PHP to echo a string completely without parsing HTML tags and characters which are normally reserved in PHP? For example, this piece of code will not echo to my screen: PHP Code:

Regex Question - Can't Get Unclosed Quote Marks Inside Of HTML Tags
I do not know much about regex.

I'm worried about lines like this:

<a href="myFile>my file</a>

There is only one quote mark in that html.

I wanted to fix this problem, so I tried this:

function command($string=false) {
$pattern = '/(.*)<a (.*)"(.*)>/i'
$replacement = '$1<$2"$3">'
$newString = preg_replace($pattern, $replacement, $string);
return $newString;
}


Copyright © 2005-08 www.BigResource.com, All rights reserved