Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using HeroDocs in php

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 218
    Comment on it

    Herodocs are useful for multi-line strings and avoiding quoting issues. It prevents from escapinging of characters in php

    EX1 )

    $sql = <<<SQL
    select *
      from TABLE_NAME
     where id =1
       and product_name = "widgets"
    SQL;
    

    O/P:

    select *
      from TABLE_NAME
     where id =1
       and product_name = "widgets"
    

    EX2)

    $sql =<<<ENDHTML
    "This is Test '"Test111"'"
    <<<ENDHTML;
    

    O/P:

      "This is Test '"Test111"'"
    

    Restriction with herodocs are :

    1- Dont leave any whitespace after the ending HERODOC

    2- Always use semicolon after HERODOC

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: