Solved

php, text before the pattern

Posted on 2013-02-04
2
232 Views
Last Modified: 2013-02-08
general question
(not looking for a pattern)
(must work with php)

for a
$pattern
and
$text

$new_text = $text before  $pattern
0
Comment
Question by:rgb192
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 38853296
This will get the text up to the first occurrence of the pattern:

$pattern_without_delimiters = "mypattern.*ends here";
$new_text = preg_replace("#^(.*?){$pattern_without_delimiters}#s", "$1", $text);

Open in new window


Update: removed preg_quote call because it would change .* to \.\*
You'll need to escape any # characters that you want to match in your pattern (with a backslash).
0
 

Author Closing Comment

by:rgb192
ID: 38870532
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now