Hi
I have a variable like this :

$fulltext = '<h1>Welcome</h1> <h2>Welcome to this website</h2> <p>Some text here. </p>';

Now I want to get only Welcome to this website in another variable.

I want to copy text between <h2> and </h2>

I don't know how to do this?
Please help me

Thanks

Recommended Answers

All 3 Replies

<?php
$reg = '/<h2>(.*)<\/h2>/s';
$fulltext="<h1>Welcome</h1> <h2>Welcome to this website</h2> <p>Some text here. </p>";
preg_match($reg,$fulltext,$matches);
print $matches[1];
?>

This will do.

Thanks a lot.
Can you give me any link to learn how to use "/" "(.*)" etc expressions?
I don't find any link related to this.

Thanks again

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.