Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: FUNCTION

  1. #1
    Join Date
    Dec 2006
    Location
    Kent, UK
    Posts
    627
    Tokens
    138
    Habbo
    Romanity

    Latest Awards:

    Default FUNCTION

    Right let me show you the function... then explain whats wrong =]

    PHP Code:
    function replace($string)
    {
     
    $pattern[0] = "{site_domain}";
     
     
    $replacement[0] = "$site_domain";
     
     
    ksort($pattern);
     
    ksort($replacement);
     
    eregi_replace("$pattern""$replacement""$string");
     return 
    $string;

    It is designed such that, when I add other values, it will do the same for them... Right, in my database is {site_domain} and im trying to replace it to be $site_domain (a previously defined variable).

    However, with and/or without the function, the end result for {site_domain} is %7bsite_domain%7d yet no where in the coding is it told to htmlspecialchars itself. And when trying to use the function but replace %7b to $, it still doesnt work -.-

    Anyone got a function that will change the {x} to $x for any variable... that works =]

    Moved by Agesilaus (Forum Moderator) from Design and Development: Please post in the correct forum.
    Last edited by Agesilaus; 23-12-2007 at 10:41 AM.
    Sangreal / Romanity ~ Habbo UK & USA
    [OurHabbo.Net Owner]
    Lewis. (Formerly xRoyal15)

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Simple answer, there the {} ?

    Secondly why the hell are you useing arrays anyway when you only have a single value?? or performing a direct string replace with the eregi command even? its kinda a waste or proccessing.

    A correct and simpler version of your code could be done with a simple
    function replace($string)
    {
    $string = str_replace("{site_domain}", $site_domain, $string);
    return $string;
    }

    tho its kinda pointless as theres no reason for it to be a function if it is really only doing one task "/ (you may as well just use the str replace function itself in there)
    Last edited by Mentor; 22-12-2007 at 06:36 PM.

  3. #3
    Join Date
    Dec 2006
    Location
    Kent, UK
    Posts
    627
    Tokens
    138
    Habbo
    Romanity

    Latest Awards:

    Default

    Like i said.. it have more variables...
    Ill be adding them as i go along, so indeed, the function is needed, its easier for when it comes to the CMS system.
    Any idea on how to make it work?
    Sangreal / Romanity ~ Habbo UK & USA
    [OurHabbo.Net Owner]
    Lewis. (Formerly xRoyal15)

  4. #4
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Ok, though the ksort and use of the ergi instead of str replace still seems unnessary?

  5. #5
    Join Date
    Dec 2006
    Location
    Kent, UK
    Posts
    627
    Tokens
    138
    Habbo
    Romanity

    Latest Awards:

    Default

    Oki, changed to preg_replace... however the function still wont work...
    Any idea how to get it to work.. i think the problem is that its being htmlspecialchars without being told to... :S
    Sangreal / Romanity ~ Habbo UK & USA
    [OurHabbo.Net Owner]
    Lewis. (Formerly xRoyal15)

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    No, its becuse your useing preg_replace instead of string... preg uses regex style patterns, which likely mans {} are read as parmiters for the replace string and in tern not replaced in the final document. why is it your so opposed to useing str_replace when replaceing strings?

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

    Latest Awards:

    Default

    I told you the code earlier..

  8. #8
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Use entors and add more str_replaces for each thing u wish to replace?

    ie
    PHP Code:
    function replace($string)
    {
    $string str_replace("{site_domain}"$site_domain$string);
    $string str_replace("{site_name}",$site_name,$string);
    return 
    $string;

    Coming and going...
    Highers are getting the better of me

  9. #9
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    str replace should support arrays just as well as any other function?

  10. #10
    Join Date
    Dec 2006
    Location
    Kent, UK
    Posts
    627
    Tokens
    138
    Habbo
    Romanity

    Latest Awards:

    Default

    PHP Code:
    function replace($string)
    {
     
    $pattern[0] = "{site_domain}";
     
    $pattern[1] = "{site_name}"
     
     
    $replacement[0] = "$site_domain";
     
    $replacement[1] = "$site_name"
     
     
    ksort($pattern);
     
    ksort($replacement);
     
     
    str_replace($pattern$replacement"$string");
     
     return 
    $string;

    Still wont replace the {site_domain} with its value -.-
    Sangreal / Romanity ~ Habbo UK & USA
    [OurHabbo.Net Owner]
    Lewis. (Formerly xRoyal15)

Page 1 of 3 123 LastLast

Posting Permissions

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