0

Preface: I cannot rename the source tags or edit their IDs. Any changes to the tags must happen after they have been fetched.

What I'm doing: using file_get_contents in PHP, I am requesting data from a remote site. This data is just two <p> tags. I need to hide or rename the second of the two <p> tags. Is this possible with PHP or jQuery?

What I'm working with:

<p>Hello my name is test</p><p>I like studying geology.</p>
Jason
  • 185
  • 1
  • 9

3 Answers3

1

You could try a php string replace

 $new_string = str_replace('</p><p>','',file_get_contents('somecontent'));
1

If you need to hide second text, you can do this with Jquery:

$('p:eq(1)').hide();

Jsfiddle

rNix
  • 2,457
  • 1
  • 22
  • 28
0

If you need to do it before render HTML, you need to parse contents and remove/replace second p tag and create a new content.

Here is a DOM parser Simple HTML DOM Parser

Find similar questions below
How to match second <a> tag in this string
How to add attribute to first P tag using PHP regular expression?

Or you can do it after rendering HTML as rNix suggested.

Community
  • 1
  • 1
Pradeep Sanjaya
  • 1,816
  • 1
  • 15
  • 23