strpos()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
traffic
Forum Newbie
Posts: 17
Joined: Fri May 23, 2003 1:18 pm

strpos()

Post by traffic »

Hello...

If I have defined $pos as:

Code: Select all

$pos = strpos ( $data, $value )
How can I find the number of characters between $pos and the next ">"...

Example:

Code: Select all

<a id="_ctl4_hlMCR" href="/Assessor/ParcelApplication/plat_redirect.asp?txtBookNo=586&txtPageNo=25&selType=Plat" target="_blank">58625</a>
The above $pos will put me right after "id=" - I need to 'add' the number of characters from "id=" through the first ">"...

The idea is to strip out the "58625"...


Thank you for any help you can give me...


...
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Code: Select all

$data = "<a id=\"_ctl4_hlMCR\" href=\"/Assessor/ParcelApplication/plat_redirect.asp?txtBookNo=586&txtPageNo=25&selType=Plat\" target=\"_blank\">58625</a>";

$posa = strpos ( $data, ">");
$posb = strpos ( $data, "<", 2);

$length = $posb - $posa;
$strip = substr($posa, $length);
$data = str_replace($strip, "", $data);
If you actually wanted to keep the '58625' then it is $strip.
There are better ways to do this using Regex.
traffic
Forum Newbie
Posts: 17
Joined: Fri May 23, 2003 1:18 pm

strpos()

Post by traffic »

Grim...

I am interested in finding a better way to do this...

The reason I was asking about the finding the 'next' ">" is that I do not know what the string is...

Code: Select all

<a id=\"_ctl4_hlMCR\" href=\"/Assessor/ParcelApplication/plat_redirect.asp?txtBookNo=586&txtPageNo=25&selType=Plat\
The only part that I know will be there is the "_ctl4_hlMCR"...
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Are you stripping content from other peoples websites?
traffic
Forum Newbie
Posts: 17
Joined: Fri May 23, 2003 1:18 pm

Content

Post by traffic »

Yes - I am stripping public records content for personal use...


...
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

I would suggest regular expressions pattern matching, if you are new to this start with something simpler like matching an email
Post Reply