Jump to content

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).

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.