1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

$x=include path?

Discussion in 'PHP' started by Adulu, Mar 17, 2011.

  1. #1
    $x="include('home/adulu/public_html/123.php');";

    echo "$x";(i'd like it print 123.php scripts)

    but it just print text ->"include('home/adulu/public_html/123.php');"

    please help. thanks
     
    Adulu, Mar 17, 2011 IP
  2. IAreOwn

    IAreOwn Active Member

    Messages:
    46
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #2
    why of course.. it should print what is in your variable $x which is the string "include('home/adulu/public_html/123.php');" set your $x to '123.php' and you'll get what you want... what really are you trying to achieve here anyway?
     
    IAreOwn, Mar 17, 2011 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    
    <?php 
    echo str_replace('/','', $_SERVER['REQUEST_URI']); // 123.php
    ?>
    
    PHP:
     
    MyVodaFone, Mar 17, 2011 IP
  4. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    example:123.php's content is <?php $y=(1+2); echo "$y"; ?>

    I hope i can
    $x="include('home/adulu/public_html/123.php');";
    echo "$x";
    rusult print is 3

    but actually is print include('home/adulu/public_html/123.php'); this is not my wish.
     
    Adulu, Mar 17, 2011 IP
  5. kajol

    kajol Well-Known Member

    Messages:
    523
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Yes.. What do you want to achieve here...? If you want to execute PHP code inside a string, use "eval" function ..
    eval($x);
     
    kajol, Mar 17, 2011 IP
  6. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #6
    my achieve
    because i'd like to determine include or not include
    $a=yes;
    if($a=="yes")
    {
    $x="include('home/adulu/public_html/123.php');";(this is wrong code that is asume)
    }
    else
    {
    $x="nothing";
    }
    ------------content------i am only can modify above code area
    echo "$x";
    (I hope this [echo "$x";] can include 123.php file)
     
    Adulu, Mar 17, 2011 IP
  7. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #7
    
    <?php
    
    ob_start();
    include('fileYouWantToStore.php');
    $a = ob_get_contents();
    ob_end_clean();
    
    echo $a;
    
    
    PHP:
     
    ThePHPMaster, Mar 17, 2011 IP
    Adulu likes this.
  8. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks so much, this is what i wish.
     
    Adulu, Mar 17, 2011 IP
    ThePHPMaster likes this.
  9. JoelLarson

    JoelLarson Peon

    Messages:
    61
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    This is less code to do what you wanted:
    ( file_get_Contents returns as a string, returns as FALSE on failure )

    <?php
    
    $file = file_get_contents('filepath/file.php');
    echo $file;
    PHP:
     
    JoelLarson, Mar 17, 2011 IP
  10. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #10
    This wouldn't execute the code, just saves it.
     
    ThePHPMaster, Mar 17, 2011 IP