post_title
B Project Kodou Ambitious 0101 Boys Meet Girl
B Project Kodou Ambitious 0102 Boys Meet Girl
B J and the Bear 0110 Lobo
B J and the Bear 0111 Crackers
B O R N To Style 0101 Homeless Boy To Rock Star Glam
B O R N To Style 0101 Homeless Boy To Rock Star Glam
I have this csv file which have these type of strings in each cell. I want to seperate the text before 4 digits in each string. And I also want 4 digits in each string. Here is the code that I came up with so far.
$file = fopen('e.csv', 'r');
while (($row = fgetcsv($file)) !== FALSE) {
$csv[] = $row;
}
$new_csv = array();
foreach ($csv as $row)
{
$n = count($csv[0]);
for ($q = 0; $q < $n; ++$q)
{
$new_row[$csv[0][$q]] = $row[$q];
$new_csv[] = $new_row;
}
$title1 = ($new_row['post_title']);
$a_title = explode(" " ,$title1);
$tot_a = count($a_title);
$i = 0;
foreach ($a_title as $session_episode) {
$session_episode1 = preg_match_all('!\d!', $session_episode, $matches);
if ($session_episode1 != 0 && $session_episode1 != '' && $session_episode1 == 4) {
$j[] = $i;
}
$i++;
}
$len = $j[0];
$a_title[$len];
echo '<pre>' . var_dump($a_title[$len]) . '</pre>';
}
In this code, it does iterate the 4 digit from each string, but only for first 2 cells. I am new to php. Can anyone help me with how I can get 4 digits from each string with these csv rows. Thanks in advance
