0

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......

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by pritaeas
0
$pattern = '%<translate RID="(.*?)">(.*?)</translate>%s';

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

0
$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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.