Jump to content

need to make function


AV1611

Recommended Posts

need to make a function out of this:

I have a script on a server that converts a bible ref to the text, which I use in another script.  I want to make a function
called verse()

all I want to do is go:

verse("John 3:16","John 3:17");
and have it create a $variable that has all the input(s)

Here is what I do now, but it is not a function:
$STIM31517 = addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage=2TIMOTHY+3:15')));
$STIM31517 .= addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage=2TIMOTHY+3:16')));
$STIM31517 .= addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage=2TIMOTHY+3:17')));

Link to comment
Share on other sites

Sorry,

Here is what I've gotten so far.  It works, but I need it to work differently.... I'll explain below:

function verse($v,$l){
    return "<span onmouseover=\"showMessage('".
addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage='.$v.''))).
"',this)\" style='cursor:default'><font color='#007700'>".$l."</font></span>";
}
$P120 = verse("2Peter+1:20","2 Pet 1:20");
$P121 = verse("2Peter+1:21","2 Pet 1:21");

this works great, but I need it to do this:  I want it to do a range of verses.  i.e. john 3:16 and 17 together.  $v has to repeat the query, then .= it to the string.  I don't know how to make $v be more than one thing... (does that make sense?) In other words, it has to repeat the query, but add the JS to the final string once

I assume I have to make $v an array? then implode?  I don't know how to do that as part of a function... I'm in over my head :X
Link to comment
Share on other sites

Passing an array to a function is simple... to me... you look like you might need a multidemensional array though. If you want to loop through $v, what are you going to do with $l? You really need to try and explain yourslef a bit clearer, sorry.
[code]
function example($arr) {
  if (is_array($arr)) {
    foreach ($arr as $val) {
      $return .= $val." ";
    }
    return $return;
  else
    return $arr;
  }
}
[/code]
Link to comment
Share on other sites

Here is the long explaination, thorpe.

I have a js that does hover text.  I have a document with lots of bible verses in it.  I want the verses to show when you hover over the verse.

It works fine the way it is, except one problem:

If you do a single verse, you get a hover hover over that verse.  if the verse is actually a range of verses, like John 3:16 AND John 3:17, then the way I have it now, I have to have both verses listed seperatly, and a separate hover.  what I really want is to show "John 3:17-17" on the web page, and have it hover the $v string for both, which means it has to query the database more than once (Or I have to re-write the query side, but can't because I use that script for other reasons as well).

I can't use
$var=$verse("John+3:16","John 3:17-17");
$var.=$verse("John+3:17","John 3:17-17");
echo $var;
because the function will repeat the JS stuff too.  so I guess I need $v to be an array, and some kind of loop.

The JS and HTML($l) will be the same no matter what, it just needs to concantenate(sp?) each verse in the range so the final output has the whole string of verses as a single string.

I don't thing I can embellish any further :P

Thanks
Link to comment
Share on other sites

well, here it is... really, it is my first real function I've written... I did a mysql login one...but that was easy...

I, for one, am proud of me...

function verse($v,$l)
{
if (is_array($v)){
foreach ($v as $val)
    {
$return .=addslashes(implode('',file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage='.$val.'')));
}
    return "<span onmouseover=\"showMessage('".$return."',this)\" style='cursor:default'><font color='#007700'>".$l."</font></span>";
}
else{
return "<span onmouseover=\"showMessage('".addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage='.$v.'')))."',this)\" style='cursor:default'><font color='#007700'>".$l."</font></span>";
}
}
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.