+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Help with PHP - preg_replace()

  1. #1
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Help with PHP - preg_replace()

    Hi,

    I'm trying to get my script to work. What I'm doing at the moment is I have a file (header.html):

    HTML Code:
    <html>
    <body>
    <title>%BOARD_NAME% &bull; %PAGE_TITLE%</title>
    </head>
    <body>
    <table border="1px" width="100%">
    <tr>
    <td>
    <h1>%BOARD_NAME%</h1>
    <p>%BOARD_DESC%</p>
    <p><a href="index.php">Index</a><br /><a href="viewf.php">View Forum</a><br /><a href="viewt.php">View Topic</a></p>
    </td>
    </tr>
    <tr>
    <td>
    <br />
    and style.php:

    PHP Code:
    <?php

    include("./config.php");

    function 
    start_page($title)
    {
        global 
    $config$func;
        
    $header $func->get_include_contents("./styles/" $config['style'] . "/header.html");
        
    $patterns = array('/%BOARD_NAME%/''/%BOARD_DESC%/''/%PAGE_TITLE%/');
        
    $replace = array($config['board_name'], $config['board_desc'], $title);
        echo 
    preg_replace($patterns$replace$header);
    }
    ?>
    Then when start_page() it called from another page it echos header.html, but with certain information changed.

    Currently I am having to type everything out manually - is there any way to get it to automatically do the arrays from what I've already got?

    en.php

    PHP Code:
    <?php

    $lang 
    = array(

    // Common language

            
    'LOGIN'    => "Log In",
            
    'REGISTER' => "Register",
            
    'WELCOME_MESSAGE' => "Welcome to the boards, we hope you enjoy as much you do",
            
    'COPYRIGHT' => "Copyright &copy; BLAH 2012",
            
    'FORUMS' => "Forums",
            
    'TOPICS' => "Topics"
    );
    ?>
    (these are not the full scripts, just enough to tell you what they do.)

    Is there anyway way to change $lang to two arrays? Eg:

    $lang = "LOGIN", "REGISTER" etc
    $lang2 = "Log in", "Register" etc

    I'm thinking a combination of print_f and preg_replace might do that.

    If you can help then thanks :D

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  2. #2
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: Help with PHP - preg_replace()

    http://callum.x10hosting.com/forums/ is where the script is located.

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  3. #3
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Help with PHP - preg_replace()

    Array_keys and Array_values o exactly what you ask. How about something like this:
    PHP Code:
    <?php 
    $header 
    $func->get_include_contents("./styles/" $config['style'] . "/header.html"); 
    $lang = array( 
            
    'LOGIN'    => "Log In"
            
    'REGISTER' => "Register"
            
    'WELCOME_MESSAGE' => "Welcome to the boards, we hope you enjoy as much you do"
            
    'COPYRIGHT' => "Copyright &copy; BLAH 2012"
            
    'FORUMS' => "Forums"
            
    'TOPICS' => "Topics" 
    ); 

    $keys array_keys($lang);
    $values array_values ($lang);
    echo 
    preg_replace($keys$values$header);
    ?>
    Last edited by lemon-tree; 04-17-2010 at 06:07 AM.

  4. #4
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: Help with PHP - preg_replace()

    Thank you! :D

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  5. #5
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Help with PHP - preg_replace()

    Those three lines could actually be truncated down to one:
    PHP Code:
    echo preg_replace(array_keys($lang), array_values($lang), $header); 

  6. #6
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: Help with PHP - preg_replace()

    Thanks :D

    It won't let me rep you

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  7. #7
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Help with PHP - preg_replace()

    I think it still thinks I don't exist, try clicking my username and you'll see

  8. #8
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: Help with PHP - preg_replace()

    "You must spread some Reputation around before giving it to lemon-tree again."

    :P

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  9. #9
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Help with PHP - preg_replace()

    Oh, fair enough, thanks for the rep.

  10. #10
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: Help with PHP - preg_replace()

    I think I repped you aaages ago in Free Hosting, cos you were being helpful

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. SUHOSIN - Use of preg_replace()
    By tr33m4n in forum Free Hosting
    Replies: 1
    Last Post: 11-14-2007, 03:34 PM
  2. preg_replace
    By YodaOfDarkness in forum Free Hosting
    Replies: 6
    Last Post: 10-09-2007, 01:48 PM
  3. New PHP and preg_replace
    By demonguard in forum Free Hosting
    Replies: 2
    Last Post: 09-25-2007, 08:30 PM
  4. Use of preg_replace() with /e modifier
    By soundsok in forum Free Hosting
    Replies: 6
    Last Post: 09-24-2007, 06:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers