Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. "." operator to join two strings...

"." operator to join two strings...

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpcomquestion
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Joan M

    Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www". $PATH = $_SERVER['DOCUMENT_ROOT'].'/'; This works wonderfully as I can see "www/". echo $PATH.'FILE.php'; This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:

    [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

    S Offline
    S Offline
    samarulraj
    wrote on last edited by
    #2
    J 1 Reply Last reply
    0
    • S samarulraj
      J Offline
      J Offline
      Joan M
      wrote on last edited by
      #3

      First of all thank you for answering. I know that I can put the / just before the file name. The idea was to avoid that: there are thousands of places with the file name but only a few with the path. I'd like to know why do this happens. I've not seen this behavior documented anywhere. Thanks again.

      [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

      https://www.robotecnik.com freelance robots, PLC and CNC programmer.

      1 Reply Last reply
      0
      • J Joan M

        Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www". $PATH = $_SERVER['DOCUMENT_ROOT'].'/'; This works wonderfully as I can see "www/". echo $PATH.'FILE.php'; This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:

        [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

        E Offline
        E Offline
        effayqueue
        wrote on last edited by
        #4

        Have you included ALL your code? This seems impossible if there is no other code between the two lines.

        J 1 Reply Last reply
        0
        • E effayqueue

          Have you included ALL your code? This seems impossible if there is no other code between the two lines.

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #5

          Why do you ask if I've included ALL the code? I've included some files in order not to repeat code. There are plenty of situations in which I'm using this. Do I'm missing something? Here we go... I know it seems incredible but it is what it happens... I'm doing something like:

          $path = DOC_ROOT.'/';
          echo $path; Here it works well.

          but if I'm doing something like:

          $path = DOC_ROOT.'/';
          $path2 = $path.'folderX'
          $path3 = $path.'folderY'

          include ($path.file1.php);
          include ($path2.file9.php);

          here it fails in each include and if I'm trying to get echoed the result it also fails. As I'm using the paths to include code, I've misunderstood at the beginning... my fault... X|

          [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

          modified on Saturday, March 19, 2011 9:19 AM

          https://www.robotecnik.com freelance robots, PLC and CNC programmer.

          E 2 Replies Last reply
          0
          • J Joan M

            Why do you ask if I've included ALL the code? I've included some files in order not to repeat code. There are plenty of situations in which I'm using this. Do I'm missing something? Here we go... I know it seems incredible but it is what it happens... I'm doing something like:

            $path = DOC_ROOT.'/';
            echo $path; Here it works well.

            but if I'm doing something like:

            $path = DOC_ROOT.'/';
            $path2 = $path.'folderX'
            $path3 = $path.'folderY'

            include ($path.file1.php);
            include ($path2.file9.php);

            here it fails in each include and if I'm trying to get echoed the result it also fails. As I'm using the paths to include code, I've misunderstood at the beginning... my fault... X|

            [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

            modified on Saturday, March 19, 2011 9:19 AM

            E Offline
            E Offline
            effayqueue
            wrote on last edited by
            #6

            don't you mean

            include ($path.'file1.php'); // added single quotes
            include ($path2.'file9.php');

            J 1 Reply Last reply
            0
            • J Joan M

              Why do you ask if I've included ALL the code? I've included some files in order not to repeat code. There are plenty of situations in which I'm using this. Do I'm missing something? Here we go... I know it seems incredible but it is what it happens... I'm doing something like:

              $path = DOC_ROOT.'/';
              echo $path; Here it works well.

              but if I'm doing something like:

              $path = DOC_ROOT.'/';
              $path2 = $path.'folderX'
              $path3 = $path.'folderY'

              include ($path.file1.php);
              include ($path2.file9.php);

              here it fails in each include and if I'm trying to get echoed the result it also fails. As I'm using the paths to include code, I've misunderstood at the beginning... my fault... X|

              [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

              modified on Saturday, March 19, 2011 9:19 AM

              E Offline
              E Offline
              effayqueue
              wrote on last edited by
              #7

              another suggestion: if you know or can calculate your folder depth (currently requested script's distance from the web root) try this:

              $sDepth='../../'; // for example
              require_once($sDepth.'file1.php');

              1 Reply Last reply
              0
              • E effayqueue

                don't you mean

                include ($path.'file1.php'); // added single quotes
                include ($path2.'file9.php');

                J Offline
                J Offline
                Joan M
                wrote on last edited by
                #8

                Yes, I'm at home now without access to the code (using pseudocode here).

                [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                1 Reply Last reply
                0
                • J Joan M

                  Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www". $PATH = $_SERVER['DOCUMENT_ROOT'].'/'; This works wonderfully as I can see "www/". echo $PATH.'FILE.php'; This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:

                  [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  Your code works fine for me (XAMPP 1.6.6a; PHP 5.2.5). Look again Monday! :)

                  Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  J 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Your code works fine for me (XAMPP 1.6.6a; PHP 5.2.5). Look again Monday! :)

                    Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                    J Offline
                    J Offline
                    Joan M
                    wrote on last edited by
                    #10

                    <?php
                    $path_root = $_SERVER['DOCUMENT_ROOT'].'/';

                    echo $path_root;
                    include($path_root.'aaa.php'); // this one works well
                    include($path_root.'bbb.php'); // this one gives me the error * (see below).
                    ?>

                    * Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:

                    [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                    https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                    L G 2 Replies Last reply
                    0
                    • J Joan M

                      <?php
                      $path_root = $_SERVER['DOCUMENT_ROOT'].'/';

                      echo $path_root;
                      include($path_root.'aaa.php'); // this one works well
                      include($path_root.'bbb.php'); // this one gives me the error * (see below).
                      ?>

                      * Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:

                      [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #11

                      Three comments: 1. that looks like a bug then, in your PHP system. 2. why do you feel a need to specify an explicit path in an include? I never do that, I use relative paths. Wouldn't

                      include('aaa.php');
                      include('bbb.php');

                      work well? 3. please try again with a backslash in $path_root. :)

                      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                      J 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        Three comments: 1. that looks like a bug then, in your PHP system. 2. why do you feel a need to specify an explicit path in an include? I never do that, I use relative paths. Wouldn't

                        include('aaa.php');
                        include('bbb.php');

                        work well? 3. please try again with a backslash in $path_root. :)

                        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                        J Offline
                        J Offline
                        Joan M
                        wrote on last edited by
                        #12

                        Luc Pattyn wrote:

                        that looks like a bug then, in your PHP system

                        :(( It had no sense to me... Strange behavior.

                        Luc Pattyn wrote:

                        why do you feel a need to specify an explicit path in an include?

                        Probably this is again a bug then... I've tried to use relative paths like '../aaa.php' and so on, but the problem here is that I'm using some files from different locations and those files seem to inherit (somehow) the original path... then the relative paths change depending on the file that is including the file that includes another file... Using the doc_root helps me avoiding this problem...

                        Luc Pattyn wrote:

                        please try again with a backslash in $path_root.

                        Done it already... it don't wants to work... X| Thank you for your answer! :thumbsup:

                        [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                        https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                        L 1 Reply Last reply
                        0
                        • J Joan M

                          Luc Pattyn wrote:

                          that looks like a bug then, in your PHP system

                          :(( It had no sense to me... Strange behavior.

                          Luc Pattyn wrote:

                          why do you feel a need to specify an explicit path in an include?

                          Probably this is again a bug then... I've tried to use relative paths like '../aaa.php' and so on, but the problem here is that I'm using some files from different locations and those files seem to inherit (somehow) the original path... then the relative paths change depending on the file that is including the file that includes another file... Using the doc_root helps me avoiding this problem...

                          Luc Pattyn wrote:

                          please try again with a backslash in $path_root.

                          Done it already... it don't wants to work... X| Thank you for your answer! :thumbsup:

                          [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #13

                          you're welcome. FYI: I typically use:

                          require\_once("includes/somename.php");
                          

                          i.e. my pages are at the top level of the web site, my dependencies one level down. Never had a problem with it. :)

                          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

                          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                          1 Reply Last reply
                          0
                          • J Joan M

                            <?php
                            $path_root = $_SERVER['DOCUMENT_ROOT'].'/';

                            echo $path_root;
                            include($path_root.'aaa.php'); // this one works well
                            include($path_root.'bbb.php'); // this one gives me the error * (see below).
                            ?>

                            * Error: : "Warning: include(C:/Program Files/EasyPHP-5.3.5.0/wwwbbb.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\EasyPHP-5.3.5.0\www\index.php on line 9 It seems to me that, for any unknown reason the last '/' is getting removed automatically after using it inside an include clause. :confused:

                            [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                            G Offline
                            G Offline
                            Graham Breach
                            wrote on last edited by
                            #14

                            $path_root is a global variable, so maybe something in the 'aaa.php' include (or another file included by that) is modifying it.

                            J 1 Reply Last reply
                            0
                            • G Graham Breach

                              $path_root is a global variable, so maybe something in the 'aaa.php' include (or another file included by that) is modifying it.

                              J Offline
                              J Offline
                              Joan M
                              wrote on last edited by
                              #15

                              Nice suggestion, I tried this the first thing... searched for all the $path_root variables in the web site in order to find any inconsistence... The only thing it can happen here is that the include clause is removing the last / in the file path. I works once, it never works again.

                              [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                              https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                              1 Reply Last reply
                              0
                              • J Joan M

                                Hello all, Here a novice trying to concatenate two strings without luck... :sigh: Note: The Document root is "www". $PATH = $_SERVER['DOCUMENT_ROOT'].'/'; This works wonderfully as I can see "www/". echo $PATH.'FILE.php'; This should show something like: "www/FILE.php"; but it shows "wwwFILE.php". Why is this happening? Any idea on what I'm doing that is not correct? Thank you in advance. :thumbsup:

                                [www.tamelectromecanica.com] Robots, CNC and PLC machines for grinding and polishing.

                                N Offline
                                N Offline
                                nickmaroulis
                                wrote on last edited by
                                #16

                                PHP has two ways for specifying strings. single quotes '' double quotes "" $car = 'Holden'; $sq = 'My car is a $car'; //My car is a $car $dq = "My car is a $car"; //My car is a Holden With double quotes the variable is inserted. If you are using an array or want to seperate a variable in double quotes use braces. $array['tv_show'] = 'American Idol'; $br = "{$array['tv_show']} is terrible but {$car}'s are awesome"; for the example above use "{$_SERVER['DOCUMENT_ROOT']}/FILE.php"; It may be that you are using windows and the interpreter could be swapping a '/' for '\'.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups