katerina Posted September 29, 2008 Share Posted September 29, 2008 Hi, I would like to print the text add the kind of heading, but I don't know how can I print. I would like something like : 1 Hello 2 Some title 3 World 1 Heading 1 My code is : $text = "<H1>Hello</H1><H2><a href='go'>some title</a></H2><H3 class='pro'>World</H3><H1>Heading 1</H1>"; $matches = array(); $numMatches = preg_match_all( '/<H(?P<level>[1-6])(?P<attrib>.*?'.'>)(?P<header>.*?)<\/H[1-6] *>/i', $text, $matches ); foreach( $matches[3] as $headline ) { print $headline."<br>"; } Thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/126305-how-can-i-print-headings/ Share on other sites More sharing options...
discomatt Posted September 29, 2008 Share Posted September 29, 2008 <pre><?php $text = "<H1>Hello</H1><H2><a href='go'>some title</a></H2><H3 class='pro'>World</H3><H1>Heading 1</H1>"; $regex = '%<h([\d])>(.+?)</h\1>%si'; $numMatches = preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); foreach( $matches as $headline ) echo "$headline[1] $headline[2]\n"; ?></pre> Quote Link to comment https://forums.phpfreaks.com/topic/126305-how-can-i-print-headings/#findComment-653125 Share on other sites More sharing options...
katerina Posted September 29, 2008 Author Share Posted September 29, 2008 Thanks a lot!! I would like to ask and something else, I am trying to insert into database these headings. MySQL Code is CREATE DATABASE `project` DEFAULT CHARACTER SET greek COLLATE greek_general_ci; USE project; CREATE TABLE headings( id_heading smallint(5) NOT NULL auto_increment, type varchar(5) NOT NULL, text TEXT DEFAULT NULL, PRIMARY KEY (id_heading) )ENGINE = innodb CHARACTER SET greek COLLATE greek_general_ci COMMENT = ''; But I have a problem in mysql with my language. I take as results '????????????????'. I use WAMPSERVER 2.0 Quote Link to comment https://forums.phpfreaks.com/topic/126305-how-can-i-print-headings/#findComment-653134 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.