Hi all, i am using preg_match_all to the ids and contents within a custom html tag, it all works fine if the contents within the tags are all in one line, but if they go over multiple lines, it doesn't match it.

here is the code and a sample of the tags:

function getTranslationID($string){
	
	$pattern = "/<translate RID=\"(.*?)\">(.*?)<\/translate>/";
	preg_match_all($pattern,$string,$matches);
	$matched['id'] = $matches[1];
	$matched['contents'] = $matches[2];
	if(!empty($matches[1])){
	    	return $matched;
	} else {
			return NULL;
		}
}
// a sample of html in php to match
<tranlslate RID="002"> contents..... ..... ..... ... whwhhw.....
;;;;;......................
................contents</translate>

//it works fine with:
<translate RID="002">contents  ... ..... ..... ..... ...</translate>

can anyone tell me what im doing wrong? thanks......

$pattern = '%<translate RID="(.*?)">(.*?)</translate>%s';

The s modifier is what you are looking for I think.

$pattern = '%<translate RID="(.*?)">(.*?)</translate>%s';

The s modifier is what you are looking for I think.

Thanks man, this worked perfectly. Is there any resource you can recommend as far as regex goes? i would really like to get a good hang of if.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.