Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a string containing:

< a href="/wiki/Bob" title="Bob" >

There are ten and more unrelated data in bettween them that i don't need. Basically, I want the title for each one placed in an arrray and they're different. I thought this would be easy, but I can't find out how to do it. Perhaps using explode() and a wildcard, but apparently you can't use a wildcard?

Any help greatly appreciated.

EDIT:I forgot to mention that the will change every week form 'Bob' for example to 'Tim'.

share|improve this question
    
Can you please show an example of some data and how you'd like it split? –  Surreal Dreams Feb 6 '11 at 17:54
    
preg_split() might be an alternative; or domdocument as you're trying to extract data from html markup... but showing us an example of what you need might help. –  Mark Baker Feb 6 '11 at 17:54
    
<th align="center" style="width:10%;"><a href="/wiki/Bob" title="Bob"><img alt="BobSquare.png" src="image" width="48" height="48" /></a><br /><a href="/wiki/Bob" title="Bob" class="mw-redirect">Bob</a> This only 10 times over and instead of Bob there are other names. I just want the naem out of it. –  Sondar Feb 6 '11 at 17:57
add comment

1 Answer

up vote 1 down vote accepted

Maybe something like this?

<?php
$string = '<th align="center" style="width:10%;"><a href="/wiki/Bob" title="Bob"><img alt="BobSquare.png" src="image" width="48" height="48" /></a><br /><a href="/wiki/Bob" title="Bob" class="mw-redirect">Bob</a>';

$title_array = array();
$explode = explode('title="', $string);
unset($title_array[0]);
foreach($title_array as $k => $v)
{
    $explode_string = explode('"', $v);
    $title_array[] = $explode_string[0];
}

print_r($title_array);
?>

Output:

Array
(
    [0] => Bob
    [1] => Bob
)

Hope that helps ;-)

share|improve this answer
    
That's great thanks :) –  Sondar Feb 6 '11 at 18:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.