Forum Moderators: coopster

Message Too Old, No Replies

Calling a function inside an array element txt str

embedding function in array text strings

         

TomFeist

1:42 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



Long story short – I don’t have access to a DB, so I’ve done what I think is the next best thing; I’ve defined my Web-link addresses in an external file (global variables) and I include the HREFlist in all PHP docs. Next, and the part that causes question, I made a (really spiffy) function that writes out the <a href…> part.

I have an array of quotes from people who are saying things and I’d like to hyperlink keywords in their quotes. Ideally, this would mean several calls to the linkWriter() function. My initial attempts culminated with me finally throwing in the towel and I just hard-coded the HTML tags, although I was able to interject the global variables into the array variables so I didn’t have to hard-code the URLs.

WORKS:
exampleArray = array(“This is a <a href=\”“.$LINK1.”\”>perfectly cool</a> <a href=\”“.$LINK2.”\”>hyperlinked example</a>.”,”2”);

DOESN’T WORK:
exampleArray = array(“This is a “.linkWriter($LINK1).”perfectly cool</a> “.linkWriter($LINK2).”hyperlinked example</a>.”,”2”);

Any thoughts on why the first one works, but not the second?

coopster

9:57 pm on Mar 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, TomFeist!

I'm guessing you are not returning a value [php.net]:

function linkWriter($link) { 
$link = '<a href="' . $link . '">';
return $link;
}

TomFeist

1:19 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



You're right! Currently, the linkWriter function just "echoes" the link, not returns it. I'll give that a try. Thanks!