html editor that give html code colouring inside php echo - php

When we use echo in PHP, the code inside the quotes is HTML.
On some HTML editors that I use, they just highlight all of the HTML in one colour, so it makes it a little confusing.
Is there any IDE that gives colouring inside echo?

The only real way you'd get confused echoing HTML is if there was a lot. You could always:
echo {
?>
HTML
<?php
}

Do you mean the colouring for text inside " "? Try PHPStorm (http://www.jetbrains.com/phpstorm/). They offer a 30 day free license to try out the product.

I'm not fully confident I understand what you want, but I believe you're asking if a code editor can also do HTML syntax-highlighting for HTML that exists inside PHP's echo/print statements. Normally not, because most editors see these as strings. However, you can embed PHP into HTML and that usually works a lot better:
<h1><?php print $someVar ?></h1>
If I misunderstood you, and you want syntax-highlighting for the web page...
There are plenty of javascript-based syntax-highlighters out there:
Rainbow
Prism
Sunlight

Try using Notepad++. It comes handy for many of the scripting languages. Here is the download link Notepad++ download link. Its free also. We use that for javascript editing. It works for php also

Related

PHPCS warning for wordpress escaping function

Could anyone please help me to resolve this issue shown in the picture ?
The message shown for that line of code means exactly what it says. If what it means by an "escaping function" is not clear, you can search the Web for lots of information about that. It's a fundamental concept in programming, and in website programming in general. You are going to need to understand it to write good, usable, robust webapps / websites.
Another place to start learning about what the message is telling you is noted right in the message: the WordPress Developer Handbook.
When you are going to print any content as output and if you did not properly escaped it then phpcs will generate error and it will say Output should be run through an escaping function. Here i am describing some information how you can escape properly
esc_html() It will be used to escaped any content with html tag. This WILL NOT display HTML content, it is meant for being used inside HTML and will remove your HTML.
<span><?php echo esc_html($title); ?></span>
esc_attr() can be used when need to escape any html tag attributes
<div id="<?php echo esc_attr($variableId);"></div>
wp_kses() When you need to keep any content with html tag then you have to use wp_kses() where you can pass an array of allowed html tag and attributes so that those allowed html tag will not be truncated while printing.
$title = '<span id="testid" class="className">This is a test content</span>'
echo wp_kses($title, ['span' => [ 'id' => []]]);
So if your output need to contain any html tag seems like svg then you can use wp_kses() with allowed html tag so that the require tag would not wipe out with the escaping method and this will fix the phpcs output error issue.

How to convert HTML tags to HTML in php

I am using tinymce editor for description. This is my html
He is charged with determining the best ways for us to visually represent our firm.
But it is displaying as it is at the front end. How can I convert it to HTML using php? I am doing this.
<p><?=$key['description'];?></p>
I used html_entity_decode($key['description']) and it worked perfectly for me.
you want to display HTML content in your PHP Page . If that is the case,
use that code inside the <xmp> tag.
Ex :
<xmp> <p><?=$key['description'];?></p> </xmp>
For better view , you can use SyntaxHighlighter ,rainbow packages
Links:
https://code.tutsplus.com/tutorials/quick-tip-how-to-add-syntax-highlighting-to-any-project--net-21099
https://craig.is/making/rainbows
Hope it helps you !!
Thanks.

How to set the value of hyperlink in a PHP Variable? [duplicate]

I am looking at getting the plain text from html. Which one should I choose, php strip_tags or simplehtmldom plaintext extraction?
One pro for simplehtmldom is support of invalid html, is that sufficient in itself?
strip_tags is sufficient for that.
Extracting text from HTML is tricky, so the best option is to use a library like Html2Text. It was built specifically for this purpose.
https://github.com/mtibben/html2text
Install using composer:
composer require html2text/html2text
Basic usage:
$html = new \Html2Text\Html2Text('Hello, "<b>world</b>"');
echo $html->getText(); // Hello, "WORLD"
You should probably use smiplehtmldom for the reason you mentioned and that strip_tags may also leave you non-text elements like javascript or css contained within script/style blocks
You would also be able to filter text from elements that aren't displayed (inline style=display:none)
That said, if the html is simple enough, then strip_tags may be faster and will accomplish the same task
If you just want a plain text rendering of a page then strip_tags is faster and simpler. If you want to do any manipulation of the text during that process, however, simplehtmldom is going to serve you better in the long run.
You may also want to remove slashes stripslashes()

Download text-only webpage

The question title says it all, after a bit of Googling and several days of tinkering with code, I cannot figure out how to download the plain text of a webpage.
Using strip_tags(); still leaves the JavaScript and CSS and trying to clean it up with regex also causes issues.
Is there any (simple or complicated) way to download a webpage (say a Wikipedia article) in plain-text using PHP?
I downloaded the page using PHP's file_get_contents(); as here:
$homepage = file_get_contents('http://www.example.com/');
As I said, I tried using strip_tags(); etc but I can't get the plain text.
I've tried using: http://millkencode.googlecode.com/svn/trunk/htmlxtractor/ContentExtractor.php to get the main content but it doesn't seem to work.
This is not nearly as easy as it seems. I'd recommend looking on something like PHP Simple HTML DOM Parser. Aside from JavaScript and CSS being hard to remove (and using RegEx for HTML is not proper) there could still be some inline styling there and stuff like that.
This, of course, is relative to the complexity of the HTML. strip_tags could be sufficient in some cases.
Use this code:
require_once('simple_html_dom.php');
$content=file_get_html('http://en.wikipedia.org/wiki/FYI');
$title=$content->find("#firstHeading",0)->plaintext ;
$text=$content->find("#bodyContent",0)->plaintext;
echo $title.$text;
http://simplehtmldom.sourceforge.net

syntax highlighting of multiline php echo statement in notepad++

I'm sure this has been answered before, but i'm tired of searching and don't want to start downloading editors and IDEs without knowing what i'm getting into.
I am just getting started writing php, and i would like to know a way to have notepad++ (or another editor, IDE if necessary) highlight the syntax of a multiline echo statement containing html. I would like to highlight the html inside of the echo.
In Norepad++, NetBeans and other IDEs that I am familiar with there is no way to make the editor highlight html inside echo if your file is recognized by the editor as a PHP file. But you can print html outside of echo statements instead so that html is highlited and use echo only to output php variables inside html. For example:
<?php
$name = 'John';
?>
<b>My name is <?php echo $name;?></b>

Categories