Hooker Posted June 12, 2006 Share Posted June 12, 2006 Im taking over development for a friends site that was all html in the past, he has about 1000 pages of html news and doesnt want to loose anything in the transfer to php, obviously i dont want to spend a few days/weeks going through each seperate html file copy and pasting bits from old news articles so i was thinking about using something along the lines of preg_replace, ive used it a couple of times for things like bb code because the only things that seem to stay constant in the files are the tags around things like "posted by" and "date" etc so i was thinking something like this: (the source would be copied and pasted into a form then this would process it)[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$output = file("$_POST['input']");$output = explode("|", $output);$find = array( "'\[b\](.*?)\[/b\]'is", "'\[link\](.*?)\[/link\]'i", "'\[link=(.*?)\](.*?)\[/link\]'i" );$replace = array( "<strong>\\1</strong>", "<a href=\"\\1\">\\1</a>", "<a href=\"\\1\">\\2</a>" );preg_replace($find,$replace,$output);echo $output[1];[/quote]obviously this is just a quick example of a way to process BB code, my question is - is there anyway to save the value of the "(.*?)" 's to a csv file or a txt file so i can load it into a db onces theyre all processed?thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/11763-preg_replace/ Share on other sites More sharing options...
poirot Posted June 12, 2006 Share Posted June 12, 2006 Yes, by using preg_match_all:[a href=\"http://www.php.net/preg_match_all\" target=\"_blank\"]http://www.php.net/preg_match_all[/a]Then just play with the matches array. Quote Link to comment https://forums.phpfreaks.com/topic/11763-preg_replace/#findComment-44509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.