adding a string to a function (noob)

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
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

adding a string to a function (noob)

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
function image_url() {
        global $the_image;
        echo getImageURL("WaterMark.php?photo=" . $the_image['filename']);
}
?>
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Well that depends on your getImageURL() function.
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

Post by trusting »

I'm not sure what you mean, Oren?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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).
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

Post 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;
}
Last edited by trusting on Mon May 14, 2007 6:06 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Pass in the data, don't make it use global.
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

Post 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).
trusting
Forum Newbie
Posts: 6
Joined: Mon May 14, 2007 4:51 pm

Post 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
Post Reply