strip left and right in php
<p>I am converting the following python into php</p>

<p>the aim is to remove scores from a string like "Liverpool 1 v 0 Everton"</p>

<pre><code>home, away = event_data.get("desc").split(' v ')

# remove scores from event desc
if home.rsplit(' ', 1)[1].isdigit() and away.split(' ', 1)[0].isdigit():
    event_name = home.rsplit(' ', 1)[0] + " v " + away.split(' ', 1)[1]
</code></pre>

<p>in php so far</p>

<pre><code>$nameArray = explode(' v ', $value['name']);

$home = $nameArray[0];
$away = $nameArray[1];

$event_name = $home . ' v ' . $away;
</code></pre>

<p>im struggling with the stipping the scores, any tips?</p>

<p>Using <code>preg_repalce</code> in PHP you can replace digits around <code>" v "</code>:</p>

<pre><code>$str = "Liverpool 1 v 0 Everton";

$event_name = preg_replace('/\h+\d+\h+v\h+\d+\h+/', ' v ', $str);

echo $event_name . "\n";
//=&gt; Liverpool v Everton
</code></pre>

php python regex