SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    could i use str_replace for this

    what im trying to do, is retrieve something like this that is save in my database

    PHP Code:
    <div id="wrap">
    <
    div id="sidebar">
    <<
    $username>> <br/>
    <<
    $avatar>> <br/>

    </
    div>
    <
    div id="content">

    fsjdflksjdf;lkasdj sdklfj s;dlkfjsd;lkfj;sdlfjs

    </div>
    </
    div
    and change it to something like this

    PHP Code:
    <div id="wrap">
    <div id="sidebar">
    <?php echo $username?> <br/>
    <?php echo $avatar?> <br/>

    </div>
    <div id="content">

    fsjdflksjdf;lkasdj sdklfj s;dlkfjsd;lkfj;sdlfjs

    </div>
    </div>
    basically i want to change wherever it says << to <?php echo and i want to change anywhere that is says >> to ;?>


    so it would work the same if i was retrieving this from my database

    PHP Code:
    <div>
    <<
    $username>>
    <
    div/> 
    and change it to this
    PHP Code:
    <div>
    <?php echo $username?>
    <div/>
    would that be possible. and it doesnt have to be << and >> it can be any indicator really. i just cant figure out how to use str_replace for this and havent found any other function

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $s = str_replace(array('<<', '>>'), array('<?php echo ', '?>'), $s);
    Or
    PHP Code:
    $s = preg_replace('/<<([^>]+)>>/i', '<?php echo \\1?>', $s);
    It seems the forum software doesn't want to allow \\1 in the second argument in preg_replace
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and where would i have to add those lines of code... say i have this example

    PHP Code:
    $result mysql_query("SELECT column_name FROM table_name WHERE user_id='1'") or die(mysql_error());

    while(
    $data mysql_fetch_array$result )) {

        
    $column$data['column_name']; 
        
         
        }

    echo 
    $column
    where would i have to add that so that it doesnt just echo

    <<sdfsdf>>

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Oh I'm sure you can figure it out if you want it to do it before the echo. Not to be rude but I cannot give you all the answers.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats cool, ill figure something out. thanks


Bookmarks

Posting Permissions

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