Get last
  • element from a string
  • I have a string variable that contains a lot of HTML markup and I want to get the last `
  • ` element from it. Im using something like: $markup = "
  • One
  • Two
  • Three
  • "; preg_match('#(.*)#ims', $markup, $matches); $lis = "
  • ".$matches[2]."
  • "; $total = explode("",$lis); $num = count($total)-2; echo $total[$num].""; This works and I get the last `
  • ` element printed. But I cant understand why I have to subtract the last 2 indexes of the array `$total`. Normally I would only subtract the last index since counting starts on index 0. What im i missing? Is there a better way of getting the last `
  • ` element from the string?
    isnt $lis value waht you want ? it seems to me that you get the same result

    以上就是Get last

  • element from a string的详细内容,更多请关注web前端其它相关文章!

    赞(0) 打赏
    未经允许不得转载:web前端首页 » HTML5 答疑

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址
  • 前端开发相关广告投放 更专业 更精准