Web Analytics Made Easy -
StatCounter Extracting from a string - CodingForum

Announcement

Collapse
No announcement yet.

Extracting from a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extracting from a string

    Hiya,

    If I have an array that has the following values:

    $array[0] = '<a href="mailto:[email protected]">You</a>';
    $array[1] = '<a href="mailto:[email protected]">Me</a>';
    $array[2] = '<a href="mailto:[email protected]">Them</a>';

    Does anyone see how I could change these so that they just show the email address. EG:

    $array[0] = '[email protected]';
    $array[1] = '[email protected]';
    $array[2] = '[email protected]';

    Seen as the actual address can be numerously different positions I doubt this can be done. But then again I have made many doubts only to find something is rather easy! lol

    Thanks in advance for any thoughts!

    Taylor.

  • #2
    PHP Code:
    $array[0] = '<a href="mailto:[email protected]">You</a>';
    $array[1] = '<a href="mailto:[email protected]">Me</a>';
    $array[2] = '<a href="mailto:[email protected]">Them</a>';

    $search[0] = '/<a href="mailto:/';
    $search[1] = '/">(.*?)<\/a>/';
    $replace '';

    $new_array preg_replace($search,$replace,$array);   
    print_r($new_array); 

    Comment

    Working...
    X