Jenksuy Posted June 12, 2013 Share Posted June 12, 2013 Hey, I am trying to insert my variable into single quote marks. the following code works but does not put the single quote marks around the variable as it is part of the variable... <?php $user_id = get_current_user_id(); $files = glob('wp-content/uploads/'.$user_id.'/*'); natcasesort($files); foreach($files as $file) { echo '<img src="/' . $file . '" onclick="fakeClick(event, document.getElementById(' . $file . '))" />'; } ?> this appears as with now single quote around the emboldened.. <img src="/wp-content/uploads/1/portfolio-sample-main-image.png" onclick="fakeClick(event, document.getElementById(wp-content/uploads/1/portfolio-sample-main-image.png))"> however how I want to appear is as follows... <img src="/wp-content/uploads/1/portfolio-sample-main-image.png" onclick="fakeClick(event, document.getElementById('wp-content/uploads/1/portfolio-sample-main-image.png'))"> as you can see with single quotes... how can I do this? Thanks Quote Link to comment Share on other sites More sharing options...
Irate Posted June 12, 2013 Share Posted June 12, 2013 (edited) echo "<img src='".$file."' onclick='fakeClick(event, document.getElementById(\"".$file."\")"; That should do the job, simply mask all output with backslashes. Edit: You need to use differing apostrophes if you are using strings within attributes. Edited my post above a bit. Edited June 12, 2013 by Irate Quote Link to comment Share on other sites More sharing options...
Jenksuy Posted June 12, 2013 Author Share Posted June 12, 2013 thanks... this hasnt seemed to work yet. it seems to put the first image in... but then stops all html after that... so something must be missing? Appreciate your help Quote Link to comment Share on other sites More sharing options...
Solution Jenksuy Posted June 12, 2013 Author Solution Share Posted June 12, 2013 Got it working thanks... your maskign with backslashes worked as follows echo '<img src="/' . $file . '" onclick="fakeClick(event, document.getElementById(\'' . $file . '\'))" />'; Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.