Remove the unwanted commented code copied from word using php [duplicate] - php

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP to clean-up pasted Microsoft input
Need to remove the code in comments
[if gte mso 9]><xml> <w:WordDocument> ..... --> [endif] -->
from my db field, when copying text from word and saving this unwanted code is coming.In Ie the source after this was not displaying as it causes display problems

try this:
$clean_string = preg_replace("/(\[if\s.*?\].*?\[endif\]\s*-->/)","",$dirty_string);

If thats the exact string you would like to clean then you can use something like this
$clean_string = preg_replace("/(\[if.+?\[endif\]\s{0,}-->)/","",$dirty_string);
Example here
http://ideone.com/cf0MG
Updated ideone link
http://ideone.com/08L6L

Take a look at the paste plugin:
[paste_remove_styles] If true, removes all style information when pasting, regardless of browser type. Pasting from Word 2000 will cause tinyMCE to error. Default is false.

Related

PHP preg_replace is outputing me the wrong result [duplicate]

This question already has answers here:
How to show <div> tag literally in <code>/<pre> tag?
(11 answers)
Closed 2 years ago.
Im actively practicing with php regex and got stuck with a replace function as it shows absolutely different results from tutorial I copied it from.
So the function preg_replace('/\{([a-z]+)\}/', '(?P<\1>[a-z-]+)', '{controller}\/{action}') should give me this result in the output: (?P<controller>[a-z-]+)\/(?P<action>[a-z-]+). phpliveregex.com confirms that https://www.phpliveregex.com/p/wIF
However, this is what my browser on my localhost is outputing me in fact: (?P[a-z-]+)\/(?P[a-z-]+).
How is that possible? Is my php broken or the preg_replace function is working differentely now? My php version is 7.4.4
Your browser interprets the <controller> and <action> as html tags and tries to parse them that leads to deleting them. see this to see how can you show tags literally using html encoding.
(?P<controller>[a-z-]+)\/(?P<action>[a-z-]+)
<br/>
(?P<controller>[a-z-]+)\/(?P<action>[a-z-]+)
You can maybe replace it with (?P<\1>[a-z-]+)

php echo not showing new lines stored in mysql [duplicate]

This question already has answers here:
how to show the content exactly as it's saved in mysql
(4 answers)
Closed 6 years ago.
I have a form with an input textbox that stores the content in the mysql database.
For example, I write in the input box:
Hello World!
Here is the new line
In the database, I find exactly the same text without any special characters ("here is..." starts in a new line in the database too).
When I call this data in a php echo, it shows it as:
Hello World! Here is the new line
What's wrong? How can I fix it? thanks
You need to pass the database string to nl2br fucntion to get the new line as break rule in HTML.
<?php
$dbSQLValue = "Hello World!\nHere is the new line"; //string retrieved from SQL
echo nl2br($dbSQLValue);
?>
New lines are not converted directly to HTML break line.
Hope this helps.
Open page source in browser and see that newlines are there, but for the browser to display them - they should not be \ns, but <br> tags or be inside a <pre> tag.
So: either convert newlines to brs via nl2br($your_var) or put the whole echo inside a <pre>.

highlight "<?php" ---- "?>" inside "<html>" --- "</html>" in notepad++? [duplicate]

This question already has answers here:
Is there anyway to have Notepad++ highlight both PHP and HTML at the same time?
(2 answers)
Closed 7 years ago.
<html>
This is file is called "example.php".<br>
<?php print "=== This is printed by a php 'print' statement<br>"; ?>
This text is after the embedded php.
</html>
When either of the html tags, its mate is found, and both are given a distinctive color.
But the php tags don't find their mates, and don't get highlighted. How can I get that behavior?
Save your file in .php extention in notepad ++.
If that does not sort the problem download the latest version of notepad++ from here.
Here : it works see :) -
Let me know if anyother issues :)

Wordpress: The plugin generated 46 characters of unexpected output during activation [duplicate]

This question already has answers here:
The plugin generated X characters of unexpected output during activation (WordPress)
(25 answers)
Closed 4 years ago.
EDIT: I also want to add that activating this plugin crashes the "Media" part of Wordpress. :D
Seriously, what am I missing here?
This is my code:
<!--[if (gte IE 6)&(lte IE 8)]>
<?php
function rw_selectivizr(){
wp_register_script('selectivizr',plugins_url('/js/selectivizr-min.js', __FILE__ ), array(), '1.0.2');
wp_enqueue_script('selectivizr');
}
add_action('wp_head', 'rw_selectivizr');
?>
<![endif]-->
I am getting the error written in the title. I don't get it...
Nothing I've been able to find online has been helpful as there are no white spaces there...
The other 14 plugins I've written are UTF-8 (someone suggested changing the encoding to ANSI, which I thought was a stupid suggestion... tried it anyway, didn't help)
This is all the code, I don't get it.
The 46 characters are coming from the HTML conditions which will get outputed.
If you're trying to register the script if it passes the HTML browser condition, it won't work, because the PHP will be executed regardless. You should check for the browser version on the PHP side.
if(preg_match('/(?i)msie [6-8]/',$_SERVER['HTTP_USER_AGENT']))
{
// include script
}
else
{
}

Any solve there to not execute </textarea> tag(which contained $values)? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to properly escape html form input default values in php?
I am facing problem on facing </textarea> element.
I am working on whole php file edit. If the php file has </textarea> tag it closes the files codes.
E.g.
$data=file_get_contents($file);
..
'<textarea>'
'.$data.'
'</textarea>'
..
The problem is:
if contain the </textarea> tag in data, my codes truncted by the tag. Because </textarea> is end tag of textarea values. Any solve there to not execute </textarea> tag(which contained $data)?
Try cleaning up $data before outputting it, such as:
'.htmlentities($data).'
Also, take a look at the available flags for the function in the PHP documentation.

Categories