PHP Syntax help

Discussion in 'PHP' started by deepman007, Jul 2, 2008.

  1. #1
    I'm getting unexpected '.' error in the following code

    <a href= "hello.php" onclick=" <?php return ShowImage('$ImagePath', . str_replace('','&quot;', str_replace(',',$GetProduct["product_Name"]))')" ?> >Click Here</a>
    Code (markup):

    Thanks
     
    deepman007, Jul 2, 2008 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    ShowImage(
        $ImagePath, 
        str_replace('','&quot;', str_replace('','',$GetProduct["product_Name"]))
    ); 
    
    PHP:
    This should work, however i cannot tell because your code is a bit messed up.

    However what i am certain of is that str_replace('', 'something', 'text') won't replace anything because you are not searching for anything, first argument in str_replace should be a string longer then one char.

    Don't know if i expressed myself clearly, i hope so.
     
    Greg Carnegie, Jul 2, 2008 IP
  3. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the correction and I have another question. is it possible to have echo statement within another echo statement ?
     
    deepman007, Jul 2, 2008 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    uhhm, for your second question, probably no, and why would there be any need for that kind of code statement?
     
    serialCoder, Jul 2, 2008 IP
  5. WebLOADER

    WebLOADER Well-Known Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #5
    
    ShowImage( $ImagePath, str_replace('','&quot;', str_replace('','',$GetProduct["product_Name"]))
    );
    PHP:
     
    WebLOADER, Jul 2, 2008 IP
  6. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Im trying to combine two statements into one.

    Code for display image;

    
    <?php echo(DisplayImage($productId, 2, $GetProduct["product_Name"], ""));
    
    Code (markup):
    Code for Pop Image:

    
    echo("<br/> <a href=\"ImagePath\" onclick=\"return ShowImage('$ImagePath','" . str_replace('"','&quot;',str_replace("'","\'",$GetProduct["product_Name"])) . "')\">View Larger Image</a>");
    
    Code (markup):
    How do you combine these two codes into one? Instead of clicking on the "View larger image" and pops up the large image, I want to click on the image and pops up a large image.
     
    deepman007, Jul 2, 2008 IP
  7. AliasXNeo

    AliasXNeo Banned

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    DisplayImage($productId, 2, $GetProduct["product_Name"], "")

    echo "<br/> <a href=\"ImagePath\" onclick=\"return ShowImage('{$ImagePath}','" . str_replace('"','&quot;',str_replace("'","\'",$GetProduct["product_Name"])) . "')\">" . DisplayImage($productId, 2, $GetProduct["product_Name"], "") . "</a>";
    PHP:
    Your code is so messy I'm not positive if that will work. I suggest putting stuff into variables and then echo'ing the variables so you can actually understand what's happening.
     
    AliasXNeo, Jul 2, 2008 IP
  8. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you very much for combining two of them to one. Would you explain how you did? why use the dot ?
     
    deepman007, Jul 2, 2008 IP
  9. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #9
    in php the dot is a concatenation operator
     
    serialCoder, Jul 2, 2008 IP
  10. deepman007

    deepman007 Peon

    Messages:
    99
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks! I didn't know you can concatenate <a href=#">. php code. </a>
     
    deepman007, Jul 2, 2008 IP