Jump to content

Function not executing


MarcusZ

Recommended Posts

I need some help with this one. Works fine when it's not a function but now something has happened.

send($reply);

function send($text)
{
global $text;
$url = "http://www.example.com";
$text = nl2br($text);
$text = str_replace("<br />","%0A",$text);
$text = rawurlencode($text);
$replyres = file_get_contents($url . "&text=" . $text);
}

Link to comment
https://forums.phpfreaks.com/topic/204192-function-not-executing/
Share on other sites

You need to either echo $replyres or return it and assign it.

 

$replyres = send($reply);

function send($text)
{
    // this is not needed global $text;
    $url = "http://www.example.com";
    $text = nl2br($text);
    $text = str_replace("<br />","%0A",$text);
    $text = rawurlencode($text);
    return file_get_contents($url . "&text=" . $text);
}

 

Should be somewhat of what you are looking to do.

You need to declare the function before you call it.

 

function send($text)

{

global $text;

$url = "http://www.example.com";

$text = nl2br($text);

$text = str_replace("<br />","%0A",$text);

$text = rawurlencode($text);

$replyres = file_get_contents($url . "&text=" . $text);

}

send($reply);

 

You need to declare the function before you call it.

 

Are you sure on that?

 

In fact, PHP parses through code first, means it loads functions no matter where they are in the code with the exception that they are not in an include file. You can place function calls anywhere you want to, as long as that function is in the current context of the code somewhere (again with the exception of being in an include).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.