SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php concatination problem

    $test = 'onclick="javascript:window.open('<?=$value['link']?>','','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=990,height=750');return false"'

    Can someone help me in concatinating this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $test 'onclick="javascript:window.open(\''.$value['link'].'\',\'\',\'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=y es,width=990,height=750\');return false"'

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If $test is a PHP variable then why are you using php tags again?

    <?=$value['link']?>

    Just use $value['link'] like this;

    $test = "onclick=
    \"javascript:window.open('{$value['link']}',
    '',
    'toolbar=no,location=no,status=no,
    menubar=no,scrollbars=yes,resizable=yes,
    width=990,height=750');return false\"'";

    Use double quotes for the whole string.
    Use {} brackets so that PHP knows you mean a PHP variable is contained inside
    Escape double quotes inside the double quotes.

    I prefer to use heredoc when writing JS inside PHP, as you can see it gets really messy and therefore error prone.

    PHP Code:
    $file_name "mylink" ;
    $test = <<<EOL
    onclick="javascript:window.open('$file_name',
    'toolbar=no,location=no,status=no,menubar=no,
    scrollbars=yes,resizable=yes,
    width=990,height=750');return false;"
    EOL;

    echo 
    $test 

  4. #4
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •