Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: FUNCTION

  1. #21
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    *Message Removed*

    Edited by Agesilaus (Forum Moderator): Please do not be rude.
    Last edited by Agesilaus; 25-12-2007 at 12:59 AM.

  2. #22
    Join Date
    Jun 2005
    Posts
    2,688
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Sangreal View Post
    Thats what i got...
    PHP Code:
    function replace($string)
    {

     
    $pattern = array("{site_domain}""{site_name}"); 

     
    $replacement = array("$site_domain""$site_name"); 

     
    str_replace($pattern$replacement$string);

     return 
    $string;

    All variables are already defined.... but the function wont work... it physically does doesnt change it to anything. Your all saying the same thing, and im saying if you listen, its not working...
    If $site_domain and $site_name are already defined in the script then you need to global them into the function:

    PHP Code:
    function replace($string) {
    global 
    $site_domain,$site_name;
    .... 

  3. #23
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Baving View Post
    If $site_domain and $site_name are already defined in the script then you need to global them into the function:

    PHP Code:
    function replace($string) {
    global 
    $site_domain,$site_name;
    .... 
    not always, you could do:

    PHP Code:
    class hi
    {
    var 
    $sitedomain;
    var 
    $site_name;
    function 
    replace($string)
    {
    whatever
    }

    and then do

    PHP Code:
    $function = new hi;
    $function->sitedomain $sitedomain;
    $function->site_name $site_name;
    $function->replace("hi"); 
    although yours is easier.

  4. #24
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Baving View Post
    If $site_domain and $site_name are already defined in the script then you need to global them into the function:

    PHP Code:
    function replace($string) {
    global 
    $site_domain,$site_name;
    .... 
    I didn't think you had to global things in unless they were in a class?

    Wow, learn something new every day =]

  5. #25
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice, View Post
    I didn't think you had to global things in unless they were in a class?

    Wow, learn something new every day =]
    neither did i, and i just learnt what global did lol.

    edit: btw, ive only seen global in a class before and didnt have a clue what it meant, so, ye.

  6. #26
    Join Date
    Jun 2005
    Posts
    2,688
    Tokens
    0

    Latest Awards:

    Default

    If you do not global outside variables into the function then the newly defined variables within the function will be returned as null.

    Example:

    PHP Code:
    $site='32';
    function 
    something($string) {
    $string $site.$string;

    The value of $site within the function would be blank / null.

  7. #27
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Baving View Post
    If you do not global outside variables into the function then the newly defined variables within the function will be returned as null.

    Example:

    PHP Code:
    $site='32';
    function 
    something($string) {
    $string $site.$string;

    The value of $site within the function would be blank / null.

    so if you did global in a class you would be able to use the variables in all of the class' functions?

  8. #28
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    I believe you need to global it on each function.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •