I'm trying to extract and assign values of CEO, Chairman and any other key positions to distinct variables. I was wondering how this can be done and what the best method to use is. Please see my code below which has a variable $keypeople but I'd like this to be further broken down into variables $CEO; $Chairman etc. depending on the roles contained in $keypeople. In the example below the $keypeople variable returns the following string:
key_people = {{unbulleted list|[[Larry Page]] ([[CEO]])|[[Eric Schmidt]] ([[Chairman]])|[[Sergey Brin]] (Director of [[Google X]] and Special Projects){{cite web|url=https://www.google.co.uk/intl/en/about/company/facts/management/ |title=Management Team - Company - Google}}}}
Any assistance in much appreciated.
<html>
<body>
<h2>Search</h2>
<form method="post">
Search: <input type="text" name="q" value="Google"/>
<input type="submit" value="Submit">
</form>
<?php
if (isset($_POST['q'])) {
$search = $_POST['q'];
$search = ucwords($search);
$search = str_replace(' ', '_', $search);
$url_2 = "http://en.wikipedia.org/w/api.php?
action=query&prop=revisions&rvprop=content&format=
json&titles=$search&rvsection=0&continue=";
$res_2 = file_get_contents($url_2);
$data_2 = json_decode($res_2);
?>
<h2>Search results for '<?php echo $search; ?>'</h2>
<?php foreach ($data_2->query->pages as $r):
?>
<?php foreach($r->revisions[0] as $a);
if (preg_match_all('/key_people += (.*)/', $a, $result)) {
$keypeople = trim($result[0][0]);
echo $keypeople;
} else {
echo 'Not found';
}
?>
<?php endforeach;
?>
<?php
}
?>
</body>
</html>
$keypeoplelook like? Can you trim your question down to just the code that has to do with this?role=name, role=name, you can useexplode(',')to split it up, thenexplode('=')to break these apart into the role and name, then use those to assign to the associative array.