删除空白php后面的字符串


remove string after a white space php

我是php的初学者,我想使用regex来删除我找到的第一个空白之后的字符串。我的代码是这样的:

<?php
   $barcode = $_POST['barcode'];
   $adress = "https://...";
   $timeout = 40;
   $ch = curl_init($adress);
   curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 
   curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    if (strpos($adress, 'https://') === 0) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    }
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $page_content = curl_exec($ch); 
    $dom = new 'DOMDocument('1.0', 'UTF-8');
    $internalErrors = libxml_use_internal_errors(true);
    $node = $dom->loadHTML($page_content);
    $listeImages = $dom->getElementsByTagName('img');
    foreach ($listeImages as $image)
    {
        $link = $dom->createElement("a");
        $href = $dom->createAttribute('srcset');
        $href->value = $image->getAttribute('srcset');
        $value_img = print( $href -> nodeValue.'<br />');
        $image->parentNode->replaceChild($link, $image);
        $link->appendChild($href);
        /*$exclusion_space_url=array(' ', ' 1x');
        $url_cleaned=$this->$value_img;
        foreach ($exclusion_space_url as $key=>$value) {
        $url_cleaned=str_replace($value," ",$url_cleaned);*/ ***what i tried to do***
        }     
    }
   curl_close($ch);
?>

结果是:

一个包含3-4行url的html页面,带有空格

感谢您的帮助

$yourString = "Your String With Space";
$str= strtok($yourString,' ');
echo $str;