0

value of $attributes['st_title'] is <a href="/physical-design-engineers">Physical Design Engineers</a>

I want to remove <a href="/physical-design-engineers"> and </a>. The final expected output is: $attributes['st_title'] = Physical Design Engineers

I am trying as follows:

    $pattern[0] = "/<a.[^>]+>/";
    $pattern[1] = '/</a>/';

    $replacement[1] = '';
    $replacement[0] = '';
    $attributes['st_title'] = preg_replace( $pattern, $replacement, $attributes['st_title'] );

But it sets $attributes['st_title'] as empty. Any idea?

6
  • 1
    (;,;) Commented Mar 27, 2018 at 5:59
  • 1
    You want to strip the tags? Commented Mar 27, 2018 at 5:59
  • 1
    Better option ~ How do you parse and process HTML/XML in PHP? Commented Mar 27, 2018 at 6:01
  • @mickmackusa got a duplicate in mind? Commented Mar 27, 2018 at 6:01
  • They will never stop coming... lost cause. Commented Mar 27, 2018 at 6:03

2 Answers 2

4

Since you want text only from the link, so use strip_tags()

echo strip_tags($text); 

https://eval.in/979039

Sign up to request clarification or add additional context in comments.

Comments

2

Use php strip_tags()

or

preg_replace("/<.*?>/", "", $attributes['st_title']);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.