Re: [PHP] Parsing HTML href-Attribute

2009-01-18 Thread Benjamin Hawkes-Lewis
On 16/1/09 23:41, Shawn McKenzie wrote: Again, I say that it won't work on URLs with spaces, like my web page.html. When I get a minute I'll fix it. I thought spaces in URLs weren't valid markup, but it seems to validate. Some small points of information: An HTML4 validator will only check

Re: [PHP] Parsing HTML href-Attribute

2009-01-18 Thread Micah Gersten
Depending on the goal, using the base tag in the head section might help: http://www.w3.org/TR/REC-html40/struct/links.html#h-12.4 Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Edmund Hertle wrote: Hey, I want to parse a href-attribute in a given String

RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
-Original Message- From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf Of Edmund Hertle Sent: Thursday, January 15, 2009 4:13 PM To: PHP - General Subject: [PHP] Parsing HTML href-Attribute Hey, I want to parse a href-attribute in a given String to check

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Boyd, Todd M. wrote: -Original Message- From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf Of Edmund Hertle Sent: Thursday, January 15, 2009 4:13 PM To: PHP - General Subject: [PHP] Parsing HTML href-Attribute Hey, I want to parse a href-attribute in a given

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Thu, Jan 15, 2009 at 5:13 PM, Edmund Hertle edmund.her...@student.kit.edu wrote: Hey, I want to parse a href-attribute in a given String to check if there is a relative link and then adding an absolute path. Example: $string = 'a class=sample [...additional attributes...]

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread mike
On Fri, Jan 16, 2009 at 10:54 AM, Eric Butera eric.but...@gmail.com wrote: You could also use DOM for this. http://us2.php.net/manual/en/domdocument.getelementsbytagname.php only if it's parseable xml :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread mike
On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote: only if it's parseable xml :) Or not! Ignore me. Supposedly this can handle HTML too. I'll have to try it next time. Normally I wind up having to use tidy to scrub a document and try to get it into xhtml and then use simplexml. I

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Fri, Jan 16, 2009 at 1:59 PM, mike mike...@gmail.com wrote: On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote: only if it's parseable xml :) Or not! Ignore me. Supposedly this can handle HTML too. I'll have to try it next time. Normally I wind up having to use tidy to scrub

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Shawn McKenzie wrote: Boyd, Todd M. wrote: -Original Message- From: farn...@googlemail.com [mailto:farn...@googlemail.com] On Behalf Of Edmund Hertle Sent: Thursday, January 15, 2009 4:13 PM To: PHP - General Subject: [PHP] Parsing HTML href-Attribute Hey, I want to parse a href

RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
-Original Message- From: Shawn McKenzie [mailto:nos...@mckenzies.net] Sent: Friday, January 16, 2009 1:08 PM To: php-general@lists.php.net Subject: Re: [PHP] Parsing HTML href-Attribute Shawn McKenzie wrote: Boyd, Todd M. wrote: -Original Message- From: farn

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Boyd, Todd M. wrote: -Original Message- From: Shawn McKenzie [mailto:nos...@mckenzies.net] Sent: Friday, January 16, 2009 1:08 PM To: php-general@lists.php.net Subject: Re: [PHP] Parsing HTML href-Attribute Shawn McKenzie wrote: Boyd, Todd M. wrote: -Original Message

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
I believe the OP wanted to leave already-absolute paths alone (i.e., only convert relative paths). The regex does not take into account fully-qualified URLs (i.e., http://www.google.com/search?q=php) and it does not determine if a given path is relative or absolute. He was wanting to take the

RE: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Boyd, Todd M.
-Original Message- From: Shawn McKenzie [mailto:nos...@mckenzies.net] Sent: Friday, January 16, 2009 2:37 PM To: php-general@lists.php.net Subject: Re: [PHP] Parsing HTML href-Attribute Hey, I want to parse a href-attribute in a given String to check if there is a relative

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Edmund Hertle
* http://www.google.com/search?q=php ... absolute path (yes, it's a URL, but treat it as absolute) * https://www.example.com/index.php ... absolute path (yes, it's a URL, but to the local server) * /index.php ... absolute path (no protocol given, true absolute path) * index.php ... relative

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Kevin Waterson
This one time, at band camp, mike mike...@gmail.com wrote: On Fri, Jan 16, 2009 at 10:58 AM, mike mike...@gmail.com wrote: only if it's parseable xml :) Or not! Ignore me. Supposedly this can handle HTML too. I'll have to try it next time. Normally I wind up having to use tidy to scrub

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Kevin Waterson
This one time, at band camp, Eric Butera eric.but...@gmail.com wrote: You could also use DOM for this. http://us2.php.net/manual/en/domdocument.getelementsbytagname.php http://www.phpro.org/examples/Get-Links-With-DOM.html Kevin -- PHP General Mailing List (http://www.php.net/) To

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Shawn McKenzie
Edmund Hertle wrote: * http://www.google.com/search?q=php ... absolute path (yes, it's a URL, but treat it as absolute) * https://www.example.com/index.php ... absolute path (yes, it's a URL, but to the local server) * /index.php ... absolute path (no protocol given, true absolute path) *

Re: [PHP] Parsing HTML href-Attribute

2009-01-16 Thread Eric Butera
On Fri, Jan 16, 2009 at 6:18 PM, Kevin Waterson ke...@phpro.org wrote: This one time, at band camp, Eric Butera eric.but...@gmail.com wrote: You could also use DOM for this. http://us2.php.net/manual/en/domdocument.getelementsbytagname.php

[PHP] Parsing HTML href-Attribute

2009-01-15 Thread Edmund Hertle
Hey, I want to parse a href-attribute in a given String to check if there is a relative link and then adding an absolute path. Example: $string = 'a class=sample [...additional attributes...] href=/foo/bar.php '; I tried using regular expressions but my knowledge of RegEx is very limited. Things

Re: [PHP] Parsing HTML href-Attribute

2009-01-15 Thread Murray
Hi Edmund, You want a regex that looks something like this: $result = preg_replace('%(href=)(|\')(?!c:/)(.+?)(|\')%', '\1\2c:/my_absolute_path\3\4', $subject); This example assumes that your absolute path begins with c:/. You would change this to whatever suits. You would also change