AV1611 Posted July 2, 2006 Share Posted July 2, 2006 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'))); Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/ Share on other sites More sharing options...
AV1611 Posted July 2, 2006 Author Share Posted July 2, 2006 Here is what I have tried so far...function verse($v){ addslashes(implode('', file('http://204.13.168.100/~baptlcom/bible/purebible.php?passage='.$v.''))); }$P120 = verse('2Peter+1:20');but it don't work :( Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52231 Share on other sites More sharing options...
trq Posted July 2, 2006 Share Posted July 2, 2006 What does [i]don't work[/i] meen? are you getting any errors? You should be. Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52236 Share on other sites More sharing options...
AV1611 Posted July 2, 2006 Author Share Posted July 2, 2006 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 onceI 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 Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52239 Share on other sites More sharing options...
trq Posted July 2, 2006 Share Posted July 2, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52243 Share on other sites More sharing options...
AV1611 Posted July 2, 2006 Author Share Posted July 2, 2006 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 :PThanks Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52247 Share on other sites More sharing options...
AV1611 Posted July 3, 2006 Author Share Posted July 3, 2006 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>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/13498-need-to-make-function/#findComment-52263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.