PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] How to cut content before sentence?

 November 20, 2022     php, preg-replace, str-replace     No comments   

Issue

I have in my content a few paragraphs and want to cut everything before when I find for example: This is a comment statement

I tried with str_replace() but this is not possible with this method and with preg_replace but on every validation my content stay untouched.

Is there any better way to do so?


Solution

str_replace will not work in you case. Try preg_replace and remove the first matching pattern -

preg_replace('/.+?(?=This is a comment statement)/', '', $your_string, 1)

Detailed explanantion



Answered By - Sougata Bose
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing