• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Parse results into a sortable table

Hi,
This script produces the following result:

... secret of a Cape Cod vacation close to their ...
... trek for a Cape Cod vacation many more people ...
... youre considering a Cape Cod vacation here are some ...

as you can see here: http://70.87.107.194/~g3crmco/aphrasetest6.php 

But what I would like is for the result to be echoed into a sortable Table (by clicking the column header (eg Col 1 and Col 2 etc.):

Col 1  |  Col 2      | Col 3 | Col 4             | Col 5 | Col 6 | Col 7
secret | of          | a     | Cape Cod vacation | close | to    | their
trek   | for         | a     | Cape Cod vacation | many  | more  | people
you’re | considering | a     | Cape Cod vacation | here  | are   | some

Can someone help me with the changes needed in the attached code to achieve that please?

Thanks!
<?php

$subject= "For decades, families in the Boston area held the secret of a Cape Cod vacation close to their hearts like a family treasure. Every Friday, scores of station wagons loaded with escapees from the city would file over the Bourne Bridge to the East Coast's most enchanting vacation spot. Today, the word is out. While local Bostonians still make the trek for a Cape Cod vacation, many more people are crowding onto this coastal gem to take advantage of its amazing Atlantic views, superb seafood, and unique New England attitude. If you're considering a Cape Cod vacation, here are some of the venues and attractions you should put on your list. ";
//$pattern= "/(\w+\s){3}Cape\sCod\svacation/";

$subjectnew = preg_replace('/[^a-zA-Z0-9 ]/','',$subject);
$pattern=  "/(\w+\s){3}cape cod vacation(\s\w+){3}/i";

preg_match_all($pattern, $subjectnew, $matches);

//var_dump($matches);
$matches = $matches[0];

foreach($matches as $val)
	echo "... " . $val . " ...<br />";
	
?>

Open in new window

0
chrisj1963
Asked:
chrisj1963
1 Solution
 
Jagadishwor DulalBraces MediaCommented:
0
 
Ray PaseurCommented:
What is the question? Are you looking for help getting a table to have the right information in the right columns?
0
 
chrisj1963Author Commented:
Ray - Yes... I want to parse each echoed result into a table. one row for each $val BUT I would like each word in $ value to be parsed into it's own column EXCEPT the main keyword phrase would stay in tact.  The result would look like table below. The number of columns would be dependent upon the number is  brackets in $pattern (in the above example bother are {3}

<table width="955" border="1" cellpadding="3">
  <tr>
    <td>Col 1</td>
    <td>Col 2</td>
    <td>Col 3</td>
    <td>Col 4</td>
    <td>Col 5</td>
    <td>Col 6</td>
    <td>Col 7</td>
  </tr>
  <tr>
    <td>secret</td>
    <td>of</td>
    <td>a</td>
    <td>Cape Cod vacation</td>
    <td>close</td>
    <td>to</td>
    <td>their</td>
  </tr>
  <tr>
    <td>trek</td>
    <td>for</td>
    <td>a</td>
    <td>Cape Cod vacation</td>
    <td>many</td>
    <td>more</td>
    <td>people</td>
  </tr>
  <tr>
    <td>youre</td>
    <td>considering</td>
    <td>a</td>
    <td>Cape Cod vacation</td>
    <td>here</td>
    <td>are</td>
    <td>some</td>
  </tr>
</table>
0
 
meenaxiCommented:
@chrisj1963  If all the result going to have  the same number of words then  u can go for following


<?php

$subject= "For decades, families in the Boston area held the secret of a Cape Cod vacation close to their hearts like a family treasure. Every Friday, scores of station wagons loaded with escapees from the city would file over the Bourne Bridge to the East Coast's most enchanting vacation spot. Today, the word is out. While local Bostonians still make the trek for a Cape Cod vacation, many more people are crowding onto this coastal gem to take advantage of its amazing Atlantic views, superb seafood, and unique New England attitude. If you're considering a Cape Cod vacation, here are some of the venues and attractions you should put on your list. ";
//$pattern= "/(\w+\s){3}Cape\sCod\svacation/";

$subjectnew = preg_replace('/[^a-zA-Z0-9 ]/','',$subject);
$pattern=  "/(\w+\s){3}cape cod vacation(\s\w+){3}/i";

preg_match_all($pattern, $subjectnew, $matches);

$matches = $matches[0];

foreach($matches as $val){
$stmt = explode(' ',$val);
echo "<br>$stmt[0] | $stmt[1] | $stmt[2] | $stmt[3] $stmt[4] $stmt[5] | $stmt[6] | $stmt[7] | $stmt[8]";
}      
      
?>
0
 
chrisj1963Author Commented:
Thank you!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now