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. - <?php
-
-
$q=$_POST['path'];
-
-
$jaar=$_POST['years'];
-
$day=$_POST['day'];
-
//echo $day."<br />";
-
$month=$_POST['month'];
-
//echo $month."<br />";
-
-
$co= $_POST['coAbr'];
-
-
$num=$_POST['Number'];
-
$lineNumbers;
-
$lineNumber;
-
-
if($_POST['Number'])
-
-
{
-
-
// open the file
-
-
$file =$q."file1.txt";
-
-
// patterns to serch the file
-
-
$preg = "\[$jaar\] $co $num;";
-
//echo"the preg is:".$preg."<br />";
-
$data=stripslashes($preg);
-
-
$lines = file($file);
-
-
$count;
-
-
if ($lines)
-
-
{
-
-
foreach($lines as $lineNumber)
-
-
{
-
-
$lineNumbers++;
-
-
$foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE);
-
-
if ($foundAMatch > 0)
-
-
{
-
-
-
$found = $matches[0][0];
-
-
$count=$lineNumber;
-
echo"The line number is : ".$lineNumber."<br />";
-
echo"The court name is:".$_POST['courtAbr']."<br />";
-
-
echo"Line from the Registry.<br /> ";
-
$words = split(" ", $lineNumber);
-
echo "File name is : ".$words[0]."<br />";
-
$lenth = strlen($words[0]) ;
-
$lineNumber1= substr($lineNumber , $lenth);
-
echo "The Line number one is : ".$lineNumber1."<br />";
-
$words4 = split(")", $lineNumber1);
-
$lenth4 = strlen($words4[0]) ;
-
echo "the lenth :".$lenth4."<br />";
-
echo "File name is : ".$words4[0]."<br />";
-
-
$lineNumber2= substr($lineNumber1 , $lenth4);
-
echo "the line num :".$lineNumber2."<br >";
-
$words5 = split(")", $lineNumber2);
-
echo $words5[0]."<br />";
-
-
}
-
-
}
-
-
}
-
}
-
-
-
-
-
-
-
-
?>
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)
2 1668 Markus 6,050
Recognized Expert Expert
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. - <?php
-
-
$q=$_POST['path'];
-
-
$jaar=$_POST['years'];
-
$day=$_POST['day'];
-
//echo $day."<br />";
-
$month=$_POST['month'];
-
//echo $month."<br />";
-
-
$co= $_POST['coAbr'];
-
-
$num=$_POST['Number'];
-
$lineNumbers;
-
$lineNumber;
-
-
if($_POST['Number'])
-
-
{
-
-
// open the file
-
-
$file =$q."file1.txt";
-
-
// patterns to serch the file
-
-
$preg = "\[$jaar\] $co $num;";
-
//echo"the preg is:".$preg."<br />";
-
$data=stripslashes($preg);
-
-
$lines = file($file);
-
-
$count;
-
-
if ($lines)
-
-
{
-
-
foreach($lines as $lineNumber)
-
-
{
-
-
$lineNumbers++;
-
-
$foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE);
-
-
if ($foundAMatch > 0)
-
-
{
-
-
-
$found = $matches[0][0];
-
-
$count=$lineNumber;
-
echo"The line number is : ".$lineNumber."<br />";
-
echo"The court name is:".$_POST['courtAbr']."<br />";
-
-
echo"Line from the Registry.<br /> ";
-
$words = split(" ", $lineNumber);
-
echo "File name is : ".$words[0]."<br />";
-
$lenth = strlen($words[0]) ;
-
$lineNumber1= substr($lineNumber , $lenth);
-
echo "The Line number one is : ".$lineNumber1."<br />";
-
$words4 = split(")", $lineNumber1);
-
$lenth4 = strlen($words4[0]) ;
-
echo "the lenth :".$lenth4."<br />";
-
echo "File name is : ".$words4[0]."<br />";
-
-
$lineNumber2= substr($lineNumber1 , $lenth4);
-
echo "the line num :".$lineNumber2."<br >";
-
$words5 = split(")", $lineNumber2);
-
echo $words5[0]."<br />";
-
-
}
-
-
}
-
-
}
-
}
-
-
-
-
-
-
-
-
?>
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.
nathj 938
Recognized Expert Contributor
My answer/suggestion is dependent on the string format being the same every time, though the length of each part can change. -
<?php
-
$lcStartString = '"1980" (5 dec 1234) shadee codes (1234)' ;
-
$lcOriginalString = $lcStartString ; // just in case you need the original
-
echo $lcStartString . '<br />' ;
-
$lcFirstLine = substr($lcStartString, 0, strpos($lcStartString, '"', 3)+1) ;
-
echo $lcFirstLine . '<br />' ;
-
$lcStartString = str_replace($lcFirstLine, "", $lcStartString) ;
-
$lcSecondLine = substr($lcStartString, 0, strpos($lcStartString, ")") +1) ;
-
echo $lcSecondLine . '<br />' ;
-
$lcStartString = str_replace($lcSecondLine, "", $lcStartString) ;
-
$lcThirdLine = substr($lcStartString, 0, strpos($lcStartString, "(")-1);
-
echo $lcThirdLine . '<br />' ;
-
$lcStartString = str_replace($lcThirdLine, "", $lcStartString) ;
-
$lcFourthLine = $lcStartString ;
-
echo $lcFourthLine . '<br />' ;
-
?>
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 will split myString up using the delimiter of 1 space
so that
|
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 strings. I wonder if someone
else had ever stumbled on it before, and if it has a good reason to
work like it is.
Both implementations take two parameters: the separator character and
the max number of splits (maxsplit). However, string.split() accept
|
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.
I would have expected the second example to have also returned an empty
|
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, the employer code
in column 23 for 29 spaces and employer description in column 53 for
30 spaces. I have tried modifying an existing file with no real
success. I haven't found anything that specifically answers my
question. Any guidance would be...
|
by: Senthil |
last post by:
Code
----------------------
string Line = "\"A\",\"B\",\"C\",\"D\"";
string Line2 = Line.Replace("\",\"","\"\",\"\"");
string CSVColumns = Line2.Split("\",\"".ToCharArray());
| |
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 empty strings in the
resulting string array.
|
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"
|
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, bytesRead)
....
Dim parts() As String = data.Split(vbCrLf)
|
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...
field1...field2...field3...
|
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() = Microsoft.VisualBasic.Strings.Split(aLine,
vbNewLine, -1, CompareMethod.Binary)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |