Jump to content

retrieve part of a string


hno

Recommended Posts

The following code will do it:

 

$start_limiter = 'http';
$end_limiter = '.com';
$a='<a href="http://www.exam.com" id="id1"  >';

# Step 1. Find the start limiter's position

$start_pos = strpos($a,$start_limiter);


# Step 2. Find the ending limiters position, relative to the start position

$end_pos = strpos($a,$end_limiter,$start_pos);


// display  http://www.exam.com
$url = substr($a, $start_pos, ($end_pos+4)-$start_pos);

// display www.exam.com
$url2 = substr($a, $start_pos+7, ($end_pos-3)-$start_pos);

echo $url."<BR>".$url2;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.