preg_match???
Moderator: General Moderators
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
preg_match???
ok, im building a code that will automatically rename a file to its <title>
this is useful when you download a site that dynamically generates its content (for example viewtopic.php?topic=435345)
now ive built it but am having problems in the most important bit, lol
ok, ive put the whole file into an array and just now need the formula, does anyone have any ideas?
for example $title = preg_match(<title>i need this</title>);
this is useful when you download a site that dynamically generates its content (for example viewtopic.php?topic=435345)
now ive built it but am having problems in the most important bit, lol
ok, ive put the whole file into an array and just now need the formula, does anyone have any ideas?
for example $title = preg_match(<title>i need this</title>);
Thsi should do it. It isn't preg_match BTW
Mark
Code: Select all
$string = "<title>something</title>";
$title = preg_replace("|<[\/\!]*?[^<>]*?>|si", "", $string);
print $title;I think you do need preg_match 
Eg
Eg
Code: Select all
<?php
$file = file_get_contents('http://forums.devnetwork.net/viewtopic.php?p=120170#120170');
preg_match('/<title>(.[^<]*)<\/title>/i', $file, $matches);
$filename = empty($matches[1]) ? 'Unknown' : $matches[1];
echo $filename;
?>
Last edited by markl999 on Fri Jul 09, 2004 9:49 am, edited 1 time in total.
As I know you are in the process of trying to learn regex, it may be good if you could try and detail/describe your regex to us, it may help us point out where you are going wrong.Bech100 wrote:Thsi should do it. It isn't preg_match BTW
MarkCode: Select all
$string = "<title>something</title>"; $title = preg_replace("|<[\/\!]*?[^<>]*?>|si", "", $string); print $title;
The regex shown does work.redmonkey wrote:As I know you are in the process of trying to learn regex, it may be good if you could try and detail/describe your regex to us, it may help us point out where you are going wrong.
I didn't realise that it was an entire HTMl document to start with that we were search.
Mark
i have tested it and it does work.
As you say, im still getting used to this stuff. I was just seeing how i could strip all html tags from something, and that is what i came up with.
So it isn't actually tailored for this job, it would work for any text contains within and type of tag.
Im not sure how this works though
Mark
As you say, im still getting used to this stuff. I was just seeing how i could strip all html tags from something, and that is what i came up with.
So it isn't actually tailored for this job, it would work for any text contains within and type of tag.
Im not sure how this works though
Code: Select all
preg_match('/<title>(.[^<]*)<\/title>/i', $file, $matches);Mark