0

I have an output like this:

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
        )

I want to know if there is any way to get result like this:

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
        )

what I want is to eliminate the html tags along with the url and just keep the name and the number at the end of the url so that i can store it and use it later. I was trying to use str_replace inside a foreach but I cant find the right way to do it or is there another way to accomplish this?

thanks

2 Answers 2

2
  1. Match the href using the RegEx: <a href='([^\']+?)'>.

  2. explode() the matched string with delimiter '/'.

  3. Get the last element which is number.

  4. Construct a new array of objects with stripped tag post and new element number.

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

Comments

0

You should use a Regular Expression, as Shubham mentioned.

Using PHP's preg_match and the following pattern, the required data can be retrieved from the post. Afterwards a new array can be created with the desired result.

#(.+)<a[^>]+?([0-9]+)'>(.+)</a>#

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.