Hi I have read some tutorials for preg_match but I cannot write patterns. Could someone help me? In the code below I need to read 80 in level="80" The bigger difficulty is that I have to make sure level="number" is within the <character > tag and make sure charUrl="r=Garona&cn=Bob" exists in the same <character > tag $data='<character battleGroup="Rampage" charUrl="r=Garona&cn=Bob" class="Hunter" classId="3" level="80" name="Bob" >'; PHP: Thanks for your help
Try <?php $data='<character battleGroup="Rampage" charUrl="r=Garona&cn=Bob" class="Hunter" classId="3" level="80" name="Bob" >'; if(preg_match('/<character.{1,30} charUrl="r=Garona&cn=Bob".{1,50}level="(\d+)"/s', $data, $match)) { print $match[1]; } ?> PHP:
That worked thanks But I'll have to write similar code later. So please help me understand this code. I ask: 1. You start the pattern with /<character => this means "<character" is required 2. ".{1,30}" means combining with a string that can be 1-30 characters long 3. ".{1,50}" the same as 2 4. what is "(\d+)"? 5. What is "/s"? Thanks in advance