문제

나는 Object Pascal에서 Siteemap Producer를하고 있으며 parse_url PHP에서 기능.

좋은 사람을 아는 사람이 있습니까?

도움이 되었습니까?

해결책

Freepascal에는 Parseuri 기능이있는 Unit Uriparser가 있습니다. 사용 방법은 예제 중 하나에서 찾을 수 있습니다. Freepascal의 출처. 또는 오래된 예 이해하기가 다소 쉽습니다.

다른 팁

I am not familiar with the parse_url function on PHP, but you might try the TIdURI class that is included with Indy (which in turn is included with most recent Delphi releases). I think they ported it to FreePascal as well.

TIdURI is a TObject descendant that encapsulates a Universal Resource Identifier, as described in the Internet Standards document:

RFC 1630 - Universal Resource Identifiers in WWW

TIdURI provides methods and properties for assembly and disassembly of URIs using the component parts that make up the URI, including: Protocol, Host, Port, Path, Document, and Bookmark.

If that does not work, please give a specific example of what you are trying to accomplish - what are you trying to parse out of a URL.

Be careful with Indy's TIdURI class. It was supposed to be a general-purpose parser, but it has a few bugs and design flaws in it that prevent it from being a fully compliant parser. I'm currently in the process of writing a new class from scratch for Indy 11 to replace TIdURI. It will be a fully compliant URI parser, and it will also suppor IRI (RFC 3987) parsing as well.

If you're using wininet.dll you can also use their InternetCrackUrl API.

The URI RFC lists this regular expression for URI parsing:

  ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
   12            3  4          5       6  7        8 9

Where the numbers are these groups:

  $1 = http:
  $2 = http
  $3 = //www.ics.uci.edu
  $4 = www.ics.uci.edu
  $5 = /pub/ietf/uri/
  $6 = <undefined>
  $7 = <undefined>
  $8 = #Related
  $9 = Related

For this URI:

  http://www.ics.uci.edu/pub/ietf/uri/#Related

The regular expression is pretty simple and uses no special features the regular expression lib has to provide, so grab one that is compatible with your pascal implementation and there you go.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top