Shortcut for echo "<pre>";print_r($myarray);echo "</pre>";

php echo
php echo variable in html
php echo new line
php echo multiple lines
php echo html
php echo variable in string
how to store echo value in variable php
echo a variable

Is there a Shortcut for

echo "<pre>";
echo "</pre>";

It is really annoying typing those just to get a readable format of an array.

This is the shortest:

echo '<pre>',print_r($arr,1),'</pre>';

The closing tag can also be omitted.

Summary of PHP echo shortcut tag <?=, The echo shortcut syntax tag is not considered a “short tag” and is permanently enabled in PHP 5.4 and up. So if you're writing code for PHP  New shortcut feature on the Echo Show. : amazonecho. r/amazonecho: /r/AmazonEcho is a community centered around the Amazon Echo, or as we like to call her - Alexa. Alexa is designed around your voice ….

Nope, you'd just have to create your own function:

function printr($data) {
   echo "<pre>";
   echo "</pre>";

Apparantly, in 2018, people are still coming back to this question. The above would not be my current answer. I'd say: teach your editor to do it for you. I have a whole bunch of debug shortcuts, but my most used is vardd which expands to: var_dump(__FILE__ . ':' . __LINE__, $VAR$);die();

You can configure this in PHPStorm as a live template.

Is it bad practice to use <?= tag in PHP?, and un html($someVar); instead of echo $someVar or using echo json_encode($​x); for JS context). This then makes <?= tags a bad practice because it means  Microsoft Edge: Keyboard shortcuts for Windows 10 and macOS by Mark Kaelin in Software on March 4, 2020, 11:45 AM PST Limiting interaction with your browser to the mouse only is terribly inefficient.

You can set the second parameter of print_r to true to get the output returned rather than directly printed:

$output = print_r($myarray, true);

You can use this to fit everything into one echo (don’t forget htmlspecialchars if you want to print it into HTML):

echo "<pre>", htmlspecialchars(print_r($myarray, true)), "</pre>";

If you then put this into a custom function, it is just as easy as using print_r:

function printr($a) {
    echo "<pre>", htmlspecialchars(print_r($a, true)), "</pre>";

Shortcut for echo "<pre>";print_r($myarray);echo , This is the shortest: echo '<pre>',print_r($arr,1),'</pre>';. The closing tag can also be omitted. One of the most common keyboard shortcuts is CTRL + ALT +DEL. This combination was originally used by IBM to reset or reboot the computer. Under Mac OS X , this key combination has no special meaning, since a reset is triggered by the Cmd+Ctrl+Switch On key or by a special reset key.

echo '<pre>' . print_r( $myarray, true ) . '</pre>';

From the print_r() docs:

When [the second] parameter is set to TRUE, print_r() will return the information rather than print it.

Echo Dot Diary: How I use iOS Shortcuts with Alexa devices, In this guide, I'll show you how I put IFTTT Webhooks to work so I could use iOS Shortcuts with Alexa-compatible devices. The Echo Show is the only Amazon Echo product with a home screen. When you’re not using it, the Show will suggest voice commands, display your events, and even bring you current events. If you don’t like what you see, you can customize the background photo and what cards the Echo Show displays when it’s not doing something else.

Probably not helpful, but if the array is the only thing that you'll be displaying, you could always set

header('Content-type: text/plain');

PHP echo() Function, Tip: The echo() function also has a shortcut syntax. Prior to PHP 5.4.0, this syntax only works with the short_open_tag configuration setting enabled. options for the shortcut file to be created-n name: The path and file name (.LNK) of the shortcut file. -c : Change existing shortcut. -r : Resolve broken shortcut. -f : Force overwrite of an existing short cut.

New shortcut feature on the Echo Show. : amazonecho, r/amazonecho: /r/AmazonEcho is a community centered around the Amazon Echo, or as we like to call her - Alexa. Alexa is designed around your voice …

How does Amazon Echo Show's new 'Tap to Alexa' feature work?, Tap to Alexa lets owners of the Echo Show tap on the device's touchscreen to access shortcuts to popular Alexa features, like the weather and 

The Administrator Shortcut Guide to VB Scripting for Windows, ExecQuery(“Select * from “ & _ WScript.Echo propValue next “​PowerManagementCapabilities: “ & _ Next WScript.Echo “​PowerManagementSupported:.

  • what exactly do you call "shortcut" and why a function doesn't suit you?
  • Actually, the output of print_r already is in a readable format. It has linebreaks and indentation. You just dont see it because you display the content as HTML. You could simply look at the generated page source for the proper formatting.
  • There are far more tedious things to do than printing a readable array format in <pre> tags.
  • @Lo'oris Well, if print_r is being used, the rest of the layout of the page /usually/ won't matter.
  • @Lo'oris Okay, that wasn't phrased very eloquently. print_r is usually used for debugging. If one is debugging, he typically isn't worried about a layout breaking for one page load.
  • Depending on the layout. Sometimes you might output stuff at the top and then gracefully print all the page below that.
  • @Lo'oris You have to take into account what the OP is doing. It seems like he doesn't even want to write a function for what he's doing; he wants to debug and print something with as few keystrokes as possible. That's why I use 1 instead of true, omit spaces between the parameters, and mention that it's possible to omit the ending tag. The point of good practice is so that you and others can easily understand and maintain your code, but why should he care about good practice if the offending code is removed immediately after he finds the value of the variable?
  • @Curtis The commas are correct. They could be periods, but echo can take multiple arguments, which is the better practice (or at least it was five years ago).
  • Format can be even more shorter - name function like "pr" - but still the best answer.
  • I added an additional param to let the script die if needed: function printpre($var,$die = 0){ echo '<pre>',print_r($var,1),'</pre>'; if($die == 1){ die(); } }
  • Also, for more context and to retain the original function name as much as possible, you could name the function "pprint_r". This is entirely up to the developer, though.
  • I am pretty sure, that is not a shortcut.
  • No, it's not a shortcut in the context of a 'one liner', however having this readily accessible in a debug library or class makes it a shortcut. Debug::dump($arg1, [$arg2, [$argN]]);