Jump to content

Kind of stuck on replace and checking empty


phpnoobie9

Recommended Posts

I have a form that I can enter in an image url:

form

<form action="test.php" method="post">
Submit Image Url:
<input type="text" name="image2" size="45" />
Submit Image Url 2:
<br>
<input type="text" name="image2" size="45" />
<input type="submit" name="preview" value="Preview" />
</form>

 

When I submit the url the php code below checks for it..the below is wrapped up in a isset submit.

This page get's the information from the form and replaces the str_replace IMAGE1 or IMAGE2 with what I entered from the url form.

 

What I want is when the image url 1 or image url 2 is empty I want it to echo nothing else I want to echo the string replacement with the img src tag.

 

Can't seem to get it to work.

 

$imageempty = "";//If no url was entered
$image1 = $_POST['image1'];//Get url from form
$image1a = "<img src=\"$image1\" width=100 height=100 >";//Insert url into image tag
	//If image 1 input box empty
	if (!empty ($image1)) {
	//If not empty show this
	$replace = str_replace ("IMAGE1",$image1a,$replace);
	} else {
	//If empty show this
	$replace = str_replace ("IMAGE2",$imageempty,$replace);
	}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.