I am getting a url and breaking the page into strings by line....

I have a line that reads as follows...

OBV N N N N N N N BR HZ N N N N N N HZ HZ N N N BR

I have broken the line down into an array of strings that are 3 charracters each

" N"." N"." N"." N"." N"." N"." N"." BR"." HZ"." N"........ etc through the line of text.

I need to dropp the spaces from the values so i end up with ......

"N"."N"."N"."N"."N"."N"."N"."BR"."HZ"."N"....etc

I am adding the value to text to create calls for gif images that SHOULD look like this,,,,,

OBV_N.gif or OBV_BR.gif

what i am getting is...

OBV%20%20N.gif
and
OBV
%20BR.gif

I can only assume that the %20 is a space.

How does one drop the space or spaces from an array value?

    I'm a n00b, so for what it's worth...

    First, if you have a string of characters that are basically delimited by spaces, then you could probably use 'explode' to create the array and then you shouldn't have the space issue at all.

    Alternatively, you could 'trim' the value if you were only looking to take the spaces off the front or end of the string:

    $myvalue=trim($myvalue);

    Otherwise, you should be able to use string replace to search for the space in the string and delete it. Something like:

    $mynewvalue = str_replace(' ', '', $oldvalue);

    Best Wishes,

    TS

      I already tried exploding the string but it still gives me the same result.

      I just tried your idea but STILL am getting the %20's leading the value I need to get,

      I was looking at "Trim" in the PHP maunal but can't get my sleep deprived brain around it.

      Thanks for the help just the same.

        If you could post some of your code, it will be easier to help you out 🙂 I suspect that it's the way you are creating the array in the first place. Based on the example you've given:

        $str = "OBV N N N N N N N BR HZ N N N N N N HZ HZ N N N BR";
        $myArray = explode(" ", $str);

        That will split your string into an array, by using the spaces as the seperator so you will have an array of values without spaces.

          I am doing the following

          $obv = $contents[22];
           //gets the line of text from the page
          echo $obv;
          //returns/
          //OBV N N N N N N N BR HZ N N N N N N HZ HZ N N N BR
          

          but when I do the calls for the variables (ie OBV[1] etc)
          The returns contain the %20

            balloontrader wrote:

            I am doing the following

            $obv = $contents[22];
             //gets the line of text from the page
            echo $obv;
            //returns/
            //OBV N N N N N N N BR HZ N N N N N N HZ HZ N N N BR
            

            but when I do the calls for the variables (ie OBV[1] etc)
            The returns contain the %20

            %20 is space if your string is urlencoded, if so u need to use urldecode, if u want to cut space form the begining and end of a string u should use trim function ...

              Got this resolved...

              was as simple as an ltrim statement.

              D O H !

              Some times I believe i over think the problem.

              Thanks for all the pointers.

              To see what I am working on check out...
              Balloon Launch Forecast

              And click the Click Here for 's launch forecast.

              It requires a session cookie for the data to be valid.

                Write a Reply...