katerina Posted September 23, 2008 Share Posted September 23, 2008 Hi, I would like to save all headings text from a string. I use MySQL and php MySQL CREATE TABLE head( id_heading smallint(5) NOT NULL auto_increment, type varchar(5) NOT NULL, textx TEXT DEFAULT NULL, PRIMARY KEY (id_HEADING) ); PHP <html> <body> <?php if (!@mysql_connect('localhost', 'root', '')) { echo " ".mysql_error(); exit; } // retrieve all h1 tags function get_h1($file){ $h1tags = preg_match_all("/(<h1.*>)(\w.*)(<\/h1>)/isxmU",$file,$patterns); $res = array(); array_push($res,$patterns[2]); array_push($res,count($patterns[2])); return $res; } $file = '<h1>Hello Wolrd</h1><h1>Hello 2 World</h1>'; $h1 = get_h1($file); // get h1 tags if($h1[1] != 0) { foreach($h1[0] as $key => $val) { $id_heading = $key; $query = "INSERT INTO head (id_image,type,textx) VALUES('.$id_heading.','h1','.htmlentities($val).')"; } } mysql_close(); ?> </body> </html> What am I doing wrong ?? It does not work. Thanks a lot Link to comment https://forums.phpfreaks.com/topic/125449-question-for-headings-please-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.