ellandrd
asked on
splitting sentence at a specific word
ive got a sentence like: "Adobe Acrobat 6.0 Professional Ver: 006.000.000"
how can i split this sentence at the word "Ver" so:
$list = array();
$list['title'] = "Adobe Acrobat 6.0 Professional"
$list['version'] = "006.000.000"
how can i split this sentence at the word "Ver" so:
$list = array();
$list['title'] = "Adobe Acrobat 6.0 Professional"
$list['version'] = "006.000.000"
ASKER
i just get:
Array
(
[0] =>
)
Array
(
[0] =>
)
Did you assign Adobe Acrobat 6.0 Professional Ver: 006.000.000 to $sentence?
ASKER
well ive got all my sentences in an array..
$list = file("list.txt");
$array_size = sizeof($list);
for($i = 0; $i < $array_size; $i++)
{
$list[$i] = trim(str_replace("\n","",$ list[$i])) ;
}
$list = array_filter($list);
for($i = 0; $i < $array_size; $i++)
{
$list = explode(' Ver: ', $list[$i]);
}
echo "<pre>";
print_r($list);
echo "</pre>";
$list = file("list.txt");
$array_size = sizeof($list);
for($i = 0; $i < $array_size; $i++)
{
$list[$i] = trim(str_replace("\n","",$
}
$list = array_filter($list);
for($i = 0; $i < $array_size; $i++)
{
$list = explode(' Ver: ', $list[$i]);
}
echo "<pre>";
print_r($list);
echo "</pre>";
Give me a few lines on the file you are grabbing from. You might only need to split a certain line (maybe the first, for instance).
ASKER
here is my txt file contents:
Adobe Reader 7.0.7 Ver: 7.0.7
Alchemy Workstation Suite
Autodesk DWG Viewer Ver: 16.1.63.106
CCleaner (remove only)
Data Access Objects (DAO) 3.5
J2SE Runtime Environment 5.0 Update 7 Ver: 1.5.0.70
Mathcad 13 Ver: 13.1.3.0
McAfee VirusScan Ver: 4.5.1
Microsoft .NET Framework 1.1 Ver: 1.1.4322
basically what i want to do is split each line at Ver, saving for example "Adobe Reader 7.0.7" into $part[0] and saving "7.0.7" into $part[1] in an array...
Adobe Reader 7.0.7 Ver: 7.0.7
Alchemy Workstation Suite
Autodesk DWG Viewer Ver: 16.1.63.106
CCleaner (remove only)
Data Access Objects (DAO) 3.5
J2SE Runtime Environment 5.0 Update 7 Ver: 1.5.0.70
Mathcad 13 Ver: 13.1.3.0
McAfee VirusScan Ver: 4.5.1
Microsoft .NET Framework 1.1 Ver: 1.1.4322
basically what i want to do is split each line at Ver, saving for example "Adobe Reader 7.0.7" into $part[0] and saving "7.0.7" into $part[1] in an array...
For every line that has Ver, this will work:
$list = file("list.txt");
$parts = array();
foreach ($list as $v)
{
$parts[] = explode(' Ver: ', $v);
}
print_r($parts);
$list = file("list.txt");
$parts = array();
foreach ($list as $v)
{
$parts[] = explode(' Ver: ', $v);
}
print_r($parts);
ASKER
ok, but some lines dont have the word Ver.. what happens then? how can i overcome that?
Do you want to just ignore the lines without Ver?
ASKER
yes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can just use explode, for instance:
$list = array();
$list = explode(' Ver: ', $sentence);
print_r($list);
although it will be $list[0] and $list[1] and not $list['title'] and $list['version'] like you have it.
Regards,
Ted