Store HTML tags in PHP variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ffclan
Forum Newbie
Posts: 10
Joined: Fri Dec 30, 2005 3:59 am

Store HTML tags in PHP variables

Post by ffclan »

How do i do that

Currently, I have this text feild.

Code: Select all

?>
<input name="textfield3" type="text" class="style18" id="textfield3" onfocus="this.blur()" value="
<?php
	  if ($image == "Yes")
	  $img_src = '<img src="http://www.fastfragclan.com/files/usr_ul/'.rawurlencode($name).'" />';
	  echo $img_src;
?>
	  " size="70" />
Mind you that $image is = to "Yes"

But the result: Inside the text field: <img src= and right next to it outside: " size="70" /> and it also displays the picture.

I want it to just display the HTML code for an image source in a textfield. I think the " inside the <img src="> tag is what's causing the problem.

Any help would be apreciated.

Thanks.
ffclan
Forum Newbie
Posts: 10
Joined: Fri Dec 30, 2005 3:59 am

Post by ffclan »

One other thing
what is the function for if statements for different values

eg: if ($car == "Toyota" or $car == "Nissan")

The point is the "OR" is it correct to put it like that?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

If I'm reading your problem correctly, you are trying to show HTML image tags inside a text input field.

If this is the case, I would personally go about it by displaying the pointy brackets (< and >) using < and >.

So for example you wanted to show this

Code: Select all

<img src="myimage.jpg" height="300" width="300">
in a text input field, you could use this code

Code: Select all

<input type="text" name="somecode" size="100" value="<img src="myimage.jpg" height="300" width="300">">
Notice I've also used " instead of ", you could dodge that using single quotation marks, but it's bad practice. For a full list of HTML equivilents to symbols, check this page out.

Hope that helps :)

Edit: Just seen your other post. You could use either OR or ||, same goes with and, you could use AND or &&.
ffclan
Forum Newbie
Posts: 10
Joined: Fri Dec 30, 2005 3:59 am

Post by ffclan »

Not working. The text feild only shows <img src=

However, the " size="70" /> dont show no more.

Thanks anyway.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

?>
<input name="textfield3" type="text" class="style18" id="textfield3" onfocus="this.blur()" value="
<?php
      if ($image == "Yes")
      $img_src = htmlentities('<img src="http://www.fastfragclan.com/files/usr_ul/'.rawurlencode($name).'" />');
      echo $img_src;
?>
      " size="70" />
ffclan
Forum Newbie
Posts: 10
Joined: Fri Dec 30, 2005 3:59 am

Post by ffclan »

Thanks, it worked great!
Post Reply