Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php编辑数组值_Php_Str Replace - Fatal编程技术网

用php编辑数组值

用php编辑数组值,php,str-replace,Php,Str Replace,我有这样一个输出: Array ( [0] => stdClass Object ( [post] => john Has site <a href='http://www.mysite.com/events/info/4240'>this is a test</a> [date_created] => 1341853220 ) [1] => stdC

我有这样一个输出:

Array
(
    [0] => stdClass Object
        (
            [post] => john Has site <a href='http://www.mysite.com/events/info/4240'>this is a test</a>
            [date_created] => 1341853220
        )

    [1] => stdClass Object
        (
            [post] => jane Has site <a href='http://www.mysite.com/events/info/1'>test venue</a>
            [date_created] => 1341849999
        )

    [2] => stdClass Object
        (
            [post] => james Has site <a href='http://www.mysite.com/events/info/4240'>this is a test</a>
            [date_created] => 1341680695
        )
我想要的是删除url中的html标记,并将名称和编号保留在url的末尾,以便我可以存储它并在以后使用它。 我试图在foreach中使用stru_replace,但我找不到正确的方法,或者有其他方法来实现这一点吗

谢谢


  • 使用正则表达式匹配href:
    您应该使用正则表达式,如Shubham所述

    使用PHP和以下模式,可以从post中检索所需的数据。之后,可以创建一个具有所需结果的新数组

    #(.+)]+?([0-9]+)”>(.+)#

    Array
    (
        [0] => stdClass Object
            (
                [post] => john Has site this is a test
                [number] => 4240
                [date_created] => 1341853220
            )
    
        [1] => stdClass Object
            (
                [post] => jane Has site test venue
                [number] => 1
                [date_created] => 1341849999
            )
    
        [2] => stdClass Object
            (
                [post] => james Has site this is a test
                [number] => 4240
                [date_created] => 1341680695
            )