473,395 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

split()

44
Hi guys am having a problem with a split(),i retrieve line from the text file
and i wanna split that line.i manage to split two words but splitting the string
enclosed on brackets it seems to be a problem to me. can someone look at my code and please help me maybe i am missing something.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.         $q=$_POST['path'];
  4.  
  5.     $jaar=$_POST['years'];
  6.     $day=$_POST['day'];
  7.     //echo $day."<br />";
  8.     $month=$_POST['month'];
  9.     //echo $month."<br />";
  10.  
  11.     $co= $_POST['coAbr'];
  12.  
  13.     $num=$_POST['Number'];
  14.     $lineNumbers;
  15.     $lineNumber;
  16.  
  17.     if($_POST['Number'])
  18.  
  19.      {
  20.  
  21.          // open the file 
  22.  
  23.          $file =$q."file1.txt";
  24.  
  25.         // patterns to serch the file
  26.  
  27.         $preg = "\[$jaar\] $co  $num;";
  28.           //echo"the preg is:".$preg."<br />";
  29.         $data=stripslashes($preg);
  30.  
  31.         $lines = file($file); 
  32.  
  33.         $count;
  34.  
  35.         if ($lines)
  36.  
  37.             {
  38.  
  39.                 foreach($lines as $lineNumber) 
  40.  
  41.                 { 
  42.  
  43.                 $lineNumbers++;
  44.  
  45.                     $foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE); 
  46.  
  47.                     if ($foundAMatch > 0) 
  48.  
  49.                     { 
  50.  
  51.  
  52.                        $found = $matches[0][0]; 
  53.  
  54.                    $count=$lineNumber;
  55.                  echo"The line number is : ".$lineNumber."<br />";
  56.                 echo"The court name is:".$_POST['courtAbr']."<br />";
  57.  
  58.                                echo"Line from the Registry.<br /> ";
  59.                 $words = split(" ", $lineNumber);
  60.                 echo "File name is : ".$words[0]."<br />";
  61.                 $lenth = strlen($words[0]) ;
  62.                 $lineNumber1= substr($lineNumber , $lenth);
  63.                 echo "The Line number one is : ".$lineNumber1."<br />";
  64.                 $words4 = split(")", $lineNumber1);
  65.                 $lenth4 = strlen($words4[0]) ;
  66.                 echo "the lenth :".$lenth4."<br />";
  67.                 echo "File name is : ".$words4[0]."<br />";
  68.  
  69.                 $lineNumber2= substr($lineNumber1 , $lenth4);
  70.                 echo "the line num :".$lineNumber2."<br >";
  71.                 $words5 = split(")", $lineNumber2);
  72.                 echo $words5[0]."<br />";        
  73.  
  74.                          }
  75.  
  76.           }
  77.  
  78.      }  
  79.       }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. ?>
the below is the one that i wanna split()
"1980" (5 dec 1234) shadee codes (1234)

i am looking to achive the following results
"1980"
(5 dec 1234)
shadee codes
(1234)
Oct 30 '08 #1
2 1635
Markus
6,050 Expert 4TB
Hi guys am having a problem with a split(),i retrieve line from the text file
and i wanna split that line.i manage to split two words but splitting the string
enclosed on brackets it seems to be a problem to me. can someone look at my code and please help me maybe i am missing something.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.         $q=$_POST['path'];
  4.  
  5.     $jaar=$_POST['years'];
  6.     $day=$_POST['day'];
  7.     //echo $day."<br />";
  8.     $month=$_POST['month'];
  9.     //echo $month."<br />";
  10.  
  11.     $co= $_POST['coAbr'];
  12.  
  13.     $num=$_POST['Number'];
  14.     $lineNumbers;
  15.     $lineNumber;
  16.  
  17.     if($_POST['Number'])
  18.  
  19.      {
  20.  
  21.          // open the file 
  22.  
  23.          $file =$q."file1.txt";
  24.  
  25.         // patterns to serch the file
  26.  
  27.         $preg = "\[$jaar\] $co  $num;";
  28.           //echo"the preg is:".$preg."<br />";
  29.         $data=stripslashes($preg);
  30.  
  31.         $lines = file($file); 
  32.  
  33.         $count;
  34.  
  35.         if ($lines)
  36.  
  37.             {
  38.  
  39.                 foreach($lines as $lineNumber) 
  40.  
  41.                 { 
  42.  
  43.                 $lineNumbers++;
  44.  
  45.                     $foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE); 
  46.  
  47.                     if ($foundAMatch > 0) 
  48.  
  49.                     { 
  50.  
  51.  
  52.                        $found = $matches[0][0]; 
  53.  
  54.                    $count=$lineNumber;
  55.                  echo"The line number is : ".$lineNumber."<br />";
  56.                 echo"The court name is:".$_POST['courtAbr']."<br />";
  57.  
  58.                                echo"Line from the Registry.<br /> ";
  59.                 $words = split(" ", $lineNumber);
  60.                 echo "File name is : ".$words[0]."<br />";
  61.                 $lenth = strlen($words[0]) ;
  62.                 $lineNumber1= substr($lineNumber , $lenth);
  63.                 echo "The Line number one is : ".$lineNumber1."<br />";
  64.                 $words4 = split(")", $lineNumber1);
  65.                 $lenth4 = strlen($words4[0]) ;
  66.                 echo "the lenth :".$lenth4."<br />";
  67.                 echo "File name is : ".$words4[0]."<br />";
  68.  
  69.                 $lineNumber2= substr($lineNumber1 , $lenth4);
  70.                 echo "the line num :".$lineNumber2."<br >";
  71.                 $words5 = split(")", $lineNumber2);
  72.                 echo $words5[0]."<br />";        
  73.  
  74.                          }
  75.  
  76.           }
  77.  
  78.      }  
  79.       }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. ?>
the below is the one that i wanna split()
"1980" (5 dec 1234) shadee codes (1234)

i am looking to achive the following results
"1980"
(5 dec 1234)
shadee codes
(1234)
ogo796, you have been warned previously about posting code without using code tags. As you have done so again, you receive you second formal warning. Carry on doing so and you will receive a ban of some kind.

Markus.
Oct 30 '08 #2
nathj
938 Expert 512MB
My answer/suggestion is dependent on the string format being the same every time, though the length of each part can change.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.      $lcStartString = '"1980" (5 dec 1234) shadee codes (1234)' ;    
  3.      $lcOriginalString = $lcStartString ; // just in case you need the original
  4.      echo $lcStartString . '<br />' ;                     
  5.      $lcFirstLine = substr($lcStartString, 0, strpos($lcStartString, '"', 3)+1) ;
  6.      echo $lcFirstLine . '<br />' ;             
  7.      $lcStartString = str_replace($lcFirstLine, "", $lcStartString) ;
  8.      $lcSecondLine = substr($lcStartString, 0, strpos($lcStartString, ")") +1) ;
  9.      echo $lcSecondLine . '<br />' ;                                  
  10.      $lcStartString = str_replace($lcSecondLine, "", $lcStartString) ;
  11.      $lcThirdLine = substr($lcStartString, 0, strpos($lcStartString, "(")-1);  
  12.      echo $lcThirdLine . '<br />' ;
  13.      $lcStartString = str_replace($lcThirdLine, "", $lcStartString) ; 
  14.      $lcFourthLine = $lcStartString ;
  15.      echo $lcFourthLine . '<br />' ;
  16. ?>
  17.  
I hope this helps you out. it's fairly obvious what is going on here but if you get stuck or this isn't the right idea then post back - using code tags - and I'll try to help out some more.

Cheers
nathj
Oct 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
9
by: Will McGugan | last post by:
Hi, I'm curious about the behaviour of the str.split() when applied to empty strings. "".split() returns an empty list, however.. "".split("*") returns a list containing one empty string. ...
2
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces,...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
4
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
14
by: Ron | last post by:
Hello, I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? .... data += ASCII.GetString(buffer, 0,...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
5
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.