Using the Period Sign to combine text string and variable - How to combine?

Discussion in 'PHP' started by pokepsw, Jan 17, 2012.

  1. #1
    Hi All, I'm a PHP Beginner and am having a hard time customizing a WP Plugin that is using the period sign "." to call a variable. Basically, it is setting the CSS Background to $url but I need to append a string to the beginning so it will work with TimThumb.

    Here's the code in the plugin:

    $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; background: transparent url(' . $url . ') no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 100px; height: 100px;"></div>';
    Code (markup):
    I want to add "<?php echo get_bloginfo('template_url');?>/timthumb.php?src=" in front of it and "&h=100&w=100&s=1" behind it.

    I tried this, but it gave me Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in error:
    $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; background: transparent url(''<?php echo get_bloginfo('template_url');?>/timthumb.php?src=' . $url . '&h=100&w=100&s=1' ') no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 100px; height: 100px;"></div>';
    Code (markup):

    Any help is GREATLY appreciated, thanks all!
     
    pokepsw, Jan 17, 2012 IP
  2. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #2
    try this:

    
    $output .= '<div style="border: 0pt none;margin: 0pt;padding: 0pt;background: transparent url("get_bloginfo(\'template_url\') . "/timthumb.php?src=" . $url . "&h=100&w=100&s=1";") no-repeat scroll 0% 0%;-moz-background-clip: border;-moz-background-origin: padding;-moz-background-inline-policy: continuous;width: 100px;height: 100px;"></div>';
    
    Code (markup):
     
    yho_o, Jan 17, 2012 IP
  3. pokepsw

    pokepsw Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Thanks for the reply!

    Unfortunately, that doesn't work. We don't need to use the get_bloginfo. Instead, we can use the hardcoded full URL, say http://www.thisdomain.com/wp-content/themes/themeone/

    I've figured it out assigning the before and after as variables $before and $after and then going . $before . $url . $after .

    But, I'd still love to know how to do it without that, especially when using another php variable.
     
    pokepsw, Jan 17, 2012 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Dupped this somehow...
     
    jestep, Jan 17, 2012 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    I think this is what you are looking for:

    
    $output .= '<div style="border: 0pt none ; margin: 0pt; padding: 0pt; background: transparent url(http://www.thisdomain.com/wp-content/themes/themeone/timthumb.php?src='.$url.'&h=100&w=100&s=1) no-repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; width: 100px; height: 100px;"></div>';
    
    PHP:
     
    jestep, Jan 17, 2012 IP
  6. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #6
    yep sure it didnt, cuz i actually messed something, anyway "jestep" post i think should work

    also try this one:

    
    $output .= "<div style='border: 0pt none;margin: 0pt;padding: 0pt;background: transparent url(http://www.thisdomain.com/wp-content/themes/themeone/timthumb.php?src=" . $url . "&h=100&w=100&s=1)no-repeat scroll 0% 0%;-moz-background-clip: border;-moz-background-origin: padding;-moz-background-inline-policy: continuous;width: 100px;height: 100px;'></div>";
    
    Code (markup):
     
    yho_o, Jan 17, 2012 IP
  7. pokepsw

    pokepsw Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    Thanks, that works! It seems like it was the quotes being the issue? Is that right?
     
    pokepsw, Jan 18, 2012 IP