1

I got the following element in a string and i want to only keep "Alex"

<p class="f10">
  <label class="fname">First name</label>
  <input class="select" type="text" value="" name="person[firstname]">
  Alex
</p>

I tried with preg_replace but i cant remove the inside element of

How i can do it?

Alex Bogias
  • 1,826
  • 2
  • 30
  • 45

3 Answers3

2
$daya= '<p class="f10">
        <label class="fname">First name</label>
        <input class="select" type="text" value="" name="person[firstname]">
        Alex
        </p>';

echo strip_tags(preg_replace("/<label\\b[^>]*>(.*?)<\\/label>/s", "", $daya));

Output will be Alex

Daya
  • 1,170
  • 10
  • 22
0
<?php

$x = '<p class="f10">
<label class="fname">First name</label>
<input class="select" type="text" value="" name="person[firstname]">
Alex
</p>';

$x = strip_tags($x);

echo str_replace('First name','',$x);

?>
Dev
  • 489
  • 5
  • 14
0

Use This code for get best result

  1. make As A string to html code $x ='First name Alex

    ';
  2. Use str_replace function

    $x = str_replace("First name", "", strip_tags($x));

  3. print Result echo $x;