Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Regular expressions in PHP

  • 06-07-2007 5: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,570 ✭✭✭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