Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 303165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:09:49+00:00 2026-05-12T07:09:49+00:00

I’m wondering if there is a shorter way of inserting text in PHP than

  • 0

I’m wondering if there is a shorter way of inserting text in PHP than

<?php
$city = "London";
?>
This website is a funky guide to <?php print $city; ?>!!!

For example, using ruby on rails, I could set

city = 'London'

somewhere in the code, and in my .erb file I could do

This website is a funky guide to <%= city %>!!!

I did read somewhere that {$city} could be used, but I tried it and it didn’t. So is there a shorter form than <?php print $var; ?> ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:09:49+00:00Added an answer on May 12, 2026 at 7:09 am

    You could use short_open_tag, which have to be enabled in your configuration, but that’s not considered as a good practice, as it only works if those are enabled — and they are not always (maybe not even by default)

    Using long tags and echo/print might be longer, yes… But I would recommend using those, and not short tags.

    Also note that you might need to escape your data, when it comes from an un-trusted source and/or might contain HTML you don’t want to get injected in the page, to avoid injections of HTML/JS (see htmlspecialchars) :


    EDIT after the comments, to add couple of things about short_open_tag :

    Why are short open tags considered (at least by me ^^ ) bad practice ?

    First of all, after some checking, they are not enabled by default :

    For PHP 5.3 :

    squale@shark:~/temp/php/php-5.3.0
    $ grep 'short_open_tag' php.ini-development
    ; short_open_tag
    short_open_tag = Off
    squale@shark:~/temp/php/php-5.3.0
    $ grep 'short_open_tag' php.ini-production
    ; short_open_tag
    short_open_tag = Off
    

    Disabled by default in either “development” or “production” settings.

    For PHP 5.2.10 (most recent version of PHP 5.2) :

    squale@shark:~/temp/php/php-5.2.10
    $ grep 'short_open_tag' php.ini-dist
    short_open_tag = On
    squale@shark:~/temp/php/php-5.2.10
    $ grep 'short_open_tag' php.ini-recommended
    ; - short_open_tag = Off           [Portability]
    short_open_tag = Off
    

    Disabled by default in the “recommended” settings

    Considering these default settings are sometimes (often ?) kept by hosting services, it is dangerous to rely on short_open_tag being activated.

    (I have myself run into problem with those being disabled… And when you are not admin of the server and don’t have required privilegies to modify that, it’s not fun ^^ )

    If you want some numbers, you can take a look at Quick survery: short_open_tag support on or off by default?

    (Not a scientific proof — but show it could be dangerous to use those for an application you’d release to the public)

    Like you said, those, when activated, conflict with XML declaration — means you have to use something like this :

    <?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
    

    Considering short open tags exists, and might be activated on the server you’ll use, you should probable not use <?xml ever, though ; too bad 🙁

    Actually, reading through the php.ini-recommended of PHP 5.2.10 :

    ; Allow the <? tag.  Otherwise, only <?php and <script> tags are recognized.
    ; NOTE: Using short tags should be avoided when developing applications or
    ; libraries that are meant for redistribution, or deployment on PHP
    ; servers which are not under your control, because short tags may not
    ; be supported on the target server. For portable, redistributable code,
    ; be sure not to use short tags.
    

    The one from PHP 6 is even more interesting :

    ; This directive determines whether or not PHP will recognize code between
    ; <? and ?> tags as PHP source which should be processed as such. It's been
    ; recommended for several years that you not use the short tag "short cut" and
    ; instead to use the full <?php and ?> tag combination. With the wide spread use
    ; of XML and use of these tags by other languages, the server can become easily
    ; confused and end up parsing the wrong code in the wrong context. But because
    ; this short cut has been a feature for such a long time, it's currently still
    ; supported for backwards compatibility, but we recommend you don't use them.
    

    (Might be the same in PHP 5.3 ; didn’t check)

    There have been rumors short open tags could be removed from PHP 6 ; considering the portion of php.ini I just posted, it probably won’t… but, still…

    To give an argument pointing to the other direction (I’ve gotta be honest, after all) : using short open tags for template files (only) is something that is often done in Zend Framework’s examples that use template files :

    In our examples and documentation, we
    make use of PHP short tags:

    That said, many developers prefer to
    use full tags for purposes of
    validation or portability. For
    instance, short_open_tag is disabled
    in the php.ini.recommended file, and
    if you template XML in view scripts,
    short open tags will cause the
    templates to fail validation.

    (source)

    On the contrary, for .php files :

    Short tags are never allowed. For
    files containing only PHP code, the
    closing tag must always be omitted

    (source)

    I hope those informations are useful, and bring some kind of answer to your comment 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.