Page 1 of 1

adding a string to a function (noob)

Posted: Mon May 14, 2007 5:15 pm
by trusting
Hi,

I'm trying to learn PHP from examples and tutorials but I'm stuck on an piece that I'm trying to add to.

Here's the chunk I want to add to that returns an image name.

Code: Select all

function image_url() {
	global $the_image;
	echo getImageURL($the_image['filename']);
}
What I'd like to do is modify this so that instead of returning just "AnyName.jpg" it will spit out "WaterMark.php?photo=AnyName.jpg"

In other words, I'd like to add the string "WaterMark.php?photo=" to the function in front of 'filename'

I've tried everything to my abilities and looked around, but I keep getting "unexpected error" or T_STRING errors.

Can anyone help me with this?

Thank-you for your time,
Rob[/b]

Posted: Mon May 14, 2007 5:18 pm
by RobertGonzalez

Code: Select all

<?php
function image_url() {
        global $the_image;
        echo getImageURL("WaterMark.php?photo=" . $the_image['filename']);
}
?>

Posted: Mon May 14, 2007 5:26 pm
by trusting
WOW! That was fast!

Thank-you, Evera.

It almost works - on output, though, I'm getting this:

/WaterMark.php%3Fphoto%3Dimage_1_xfull.jpg

Is there anyway to tame the ? and = characters so they read as such?

Thanks again,
Rob

Posted: Mon May 14, 2007 5:27 pm
by Oren
Well that depends on your getImageURL() function.

Posted: Mon May 14, 2007 5:33 pm
by trusting
I'm not sure what you mean, Oren?

Posted: Mon May 14, 2007 5:35 pm
by RobertGonzalez
urldecode(), though the getIMageUrl() function should probably be modified if that is not what you want out of it (in fact, I'd bet that function has a call to urlencode() in it somewhere).

Posted: Mon May 14, 2007 6:01 pm
by trusting
You are correct, there are a few references to urlencode().

I read the PHP documentation on the the two functions urlencode() and urldecode(). I understand what they do now but I'm not sure how to implement it.

I've tried a few combinations based on the examples and came up with the below, but it's still spitting out "WaterMark.php/%3Fphoto/%3Dimage_1_full.jpg"

Code: Select all

function image_url() { 
        global $the_image; 
        echo getImageURL(urldecode("WaterMark.php/?photo/=" . $the_image['filename'])); 
}
Am I misunderstanding the logic?

I should have added that the getImageURL function looks like this:

Code: Select all

function getImageURL($filename) {
	global $donsimg_base_path;
	global $IMAGE_FOLDER;
	
	$encodedFilename = implode("/", array_map("rawurlencode", explode("/", $filename)));
	return $donsimg_base_path . rawurlencode($IMAGE_FOLDER) . '/' . $encodedFilename;
}

Posted: Mon May 14, 2007 6:04 pm
by feyd
Pass in the data, don't make it use global.

Posted: Mon May 14, 2007 6:15 pm
by trusting
Thanks feyd - can you elaborate?

This is all completely new to me (I think I may have jumped in over my head on the example I am using to learn).

Posted: Mon May 14, 2007 6:57 pm
by trusting
thanks folks!

I've got it running now. I figured out how to use the urldecode()

I must say this is the most responsive Board I've ever been on.

Thanks again, all
Rob