Vaibhav Bhanushali
Vaibhav Bhanushali

Reputation: 653

Error using image in php strings

Hello i am newbie in php I am having a simple php error I did google. but wasnt able to figure out the exact keywords

 <?php
 $vtext="<img alt="" src="/wp-content/themes/9GAG/images/smileynearvote.JPG" style="width: 15px; height: 17px; " />";
 ?>

This is how i call it

 <?php echo $vtext ?>

But when i use this i get an Internal server Error

i did google only founded that how to create an image with php

but didnt find how to use it string

My cms is wordpress

Upvotes: 0

Views: 49

Answers (2)

Musa
Musa

Reputation: 97707

You have to escape the " in your string

$vtext="<img alt=\"\" src=\"/wp-content/themes/9GAG/images/smileynearvote.JPG\" style=\"width: 15px; height: 17px; \" />";

Read more http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double

Upvotes: 1

Jason McCreary
Jason McCreary

Reputation: 73011

You need to escape your " (double quotes) or enclose the entire string in ' single quotes:

 $vtext = '<img alt="" src="/wp-content/themes/9GAG/images/smileynearvote.JPG" style="width: 15px; height: 17px; " />';

I encourage you to read more about Strings in PHP.

Note: This may not be the only error. When asking about errors you should always post the full error message and the offending line and the line above it.

Upvotes: 2

Related Questions