-1

i wanna change 1 word in my P tag, how can i change the specific word in p tag?

i need to replace 1 word in this tag.

  $tehra='/word/';
    echo preg_replace($tehra, 'word i want to change', 'my paragraph',1);
  • The `'my paragraph'` string has no `word` in it. – Wiktor Stribiżew Oct 28 '19 at 10:07
  • [Parsing HTML with regex is a hard job](https://stackoverflow.com/a/4234491/372239) HTML and regex are not good friends. Use a parser, it is simpler, faster and much more maintainable. See: http://php.net/manual/en/class.domdocument.php – Toto Oct 28 '19 at 10:25

1 Answers1

-1

You have the replacement and subject back to front

  $tehra='@(word)@';
  echo preg_replace( $tehra, 'my paragraph', 'The sentence with the word i want to change' );

Will yield:

The sentence with the my paragraph i want to change
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46