Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Regular expressions in PHP

  • 06-07-2007 06:42PM
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    Sorry to post without due research but I have to get this done very quickly and regular expressions are difficult :confused:

    I'm trying to replace a value in a variable that says "$column_x" (where x is a number) with its actual variable called $column_x. There are a bunch of these with different numbers.

    So for example:
    $column_0 = "hello";
    $column_1 = "aloha";
    
    $string = "English: $column_0. Hawaii: $column_1";
    

    So I do:
    ereg_replace("\$column_[:digit:]", ......................

    but don't know how to finish it. Essentially I'll have to refer back to [:digit:] but have no idea how to do that....

    Any takers?


Comments

  • Registered Users, Registered Users 2 Posts: 6,653 ✭✭✭daymobrew


    Do you need to do the ereg_replace? Assignment like you show will expand the variables (as long as they are inside double quotes).
    [PHP]<?php
    $column_0 = "hello";
    $column_1 = "aloha";

    // using double quotes will expand the variables.
    $string = "English: $column_0. Hawaii: $column_1";
    echo $string;
    echo '<br />';
    // Now use single quotes so that variables are not expanded.
    $string = 'English: $column_0. Hawaii: $column_1';
    echo $string, "\n";
    ?>
    [/PHP] This produces:
    English: hello. Hawaii: aloha
    English: $column_0. Hawaii: $column_1
    


Advertisement