rgb192
asked on
convert html into regular text
nl2br(strip_tags($str, '<br>'));
can convert
<br>
<p>hi how are you<p>
<b>bold</b>
into regular text
using a php function
but I want to convert a more complex input
<br>
<p>hi how are you
<h1>h1 tag</h1>
<h2>h2 tag</h2>
<h3>h3 tag</h3>
<p>
<b>bold</b>
can convert
<br>
<p>hi how are you<p>
<b>bold</b>
into regular text
using a php function
but I want to convert a more complex input
<br>
<p>hi how are you
<h1>h1 tag</h1>
<h2>h2 tag</h2>
<h3>h3 tag</h3>
<p>
<b>bold</b>
Please show us exactly what you want the output to be from converting this code snippet.
<br>
<p>hi how are you
<h1>h1 tag</h1>
<h2>h2 tag</h2>
<h3>h3 tag</h3>
<p>
<b>bold</b>
You can find many free html2text converters if you are googling around.
For example here is one script (under Eclipse Public License) which looks quite simple and reasonable.
Just use it like this:
For example here is one script (under Eclipse Public License) which looks quite simple and reasonable.
Just use it like this:
require("html2text.php");
...
$text = convert_html_to_text ($html);
ASKER
$before='
<br>
<p>hi how are you
<h1>h1 tag</h1>
<h2>h2 tag</h2>
<h3>h3 tag</h3>
<p>
<b>bold</b>
';
output:
hi how are you
h1 tag
h2 tag
h3 tag
bold
and I dont know how to but $before in
$str = <<<ENDSTRING
ENDSTRING
(that is from your previous answer)
<br>
<p>hi how are you
<h1>h1 tag</h1>
<h2>h2 tag</h2>
<h3>h3 tag</h3>
<p>
<b>bold</b>
';
output:
hi how are you
h1 tag
h2 tag
h3 tag
bold
and I dont know how to but $before in
$str = <<<ENDSTRING
ENDSTRING
(that is from your previous answer)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is called heredoc syntax.
$str = <<<ENDSTRING
-- heredoc stuff is contained in
-- the lines before the ENDSTRING
ENDSTRING;
The rules for heredoc are shown here:
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
It is VERY useful for things like forms, etc. Variable substitution occurs inside heredoc strings and quotes do not need to be escaped.
$str = <<<ENDSTRING
-- heredoc stuff is contained in
-- the lines before the ENDSTRING
ENDSTRING;
The rules for heredoc are shown here:
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
It is VERY useful for things like forms, etc. Variable substitution occurs inside heredoc strings and quotes do not need to be escaped.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hai,
Just use the function " strip_tags($str) " need not to pass another arguments
Just use the function " strip_tags($str) " need not to pass another arguments
@vimalmaria: Without nl2br() the output is: hi how are you h1 tag h2 tag h3 tag bold because HTML treats new line characters (indeed all white space) like blanks.
That is somewhat different from:
hi how are you
h1 tag
h2 tag
h3 tag
bold
That is somewhat different from:
hi how are you
h1 tag
h2 tag
h3 tag
bold
ASKER
Thanks, I have a similar question
I want to send the £ symbol without utf-8 encoding
https://www.experts-exchange.com/questions/26864165/I-want-to-send-the-symbol-without-utf-8-encoding.html
ASKER
Thanks, I have a similar question
I want to send the £ symbol without utf-8 encoding
https://www.experts-exchange.com/questions/26864165/I-want-to-send-the-symbol-without-utf-8-encoding.html
I want to send the £ symbol without utf-8 encoding
https://www.experts-exchange.com/questions/26864165/I-want-to-send-the-symbol-without-utf-8-encoding.html
I think in PHP would be something like this:
Open in new window