At the client’s side, sometimes (i.e., not always) data comes in a wrapper (tag) pre
, is it possible to somehow remove this tag (on the server side!), But leave the content as it is?
|
4 answers
Like this:
$pre = $_REQUEST["CLIENT_DATA"]; $nopre = substr($pre,strlen("<pre>")); $nopre = substr($nopre,0, strlen($nopre)-strlen("</pre>"));
:-)
- and this will work if we assume there was no pre, i.e. Anyway content need to get the same? Keyword sometimes - Smash
- Well then add
if(substr($pre,0, strlen("<pre>"))=="<pre>")
- Chad
|
Well, if the <pre>
comes not html\xml
, then there is a great function strip_tags
.
$content = strip_tags($content, '<pre>'); // удалить только <pre>
- Alas, it comes exactly html \ xml. I see a way out only in the editing on the client, but how to determine that two pre in a row are now this is a mystery. - Smash
- $ ($ ("user data input"). val ()). children ("pre"). size ()> 0? - Chad
- The answer is wrong. Your example will remove all tags EXCEPT the
<pre>
. - Visman
|
$content = preg_replace('/^(<pre[^>]+>)+/', '', $content); $content = preg_replace('/(<\/pre>)+$/', '', $content);
If the client copy-paste is very, very crooked.
|
If you are using jQuery, then I would suggest this option - replacing the pre tag (methods .replaceWith () .replaceAll () ) with something more suitable for you.
|
Fatal error: Call to undefined function length()
- Smash