0

I have a text which can contain HTML tags. I want to be able to view it in plain text without html tags being parsed by browser exactly the way HTML code viewers do.

for example: replacing <div> with <span><</span><span>d</span><span>i</span><span></span>v<span>></span>.

the text may also contain utf-8 characters like Arabic or Farsi. and also all tags must be replaced.

for example:

there is no html tags in this line.

the following line is in farsi:
این یک متن نمونه است به زبان فارسی

<div>
    <label>
        This is a sample text.
    </label>
</div>

the last 4 tags must be replaced in the above code and also the farsi characters must be still readable.

1 Answer 1

5

http://php.net/manual/en/function.htmlentities.php

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.