Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

preg_replace everything after and including a phrase

Featured Replies

Hello!

 

I'm making a blog, and I want to be able to manually set a cutoff point. For example, in the post, you put a <!-- more -->, just like in wordpress, and then you use preg_replace or something to change that and everything after it into a single "...". At the moment, I'm using a simple substr, but I'm worried that that might cut off an <img /> or something like that. Any advice, tips, tutorial or just straight up code?

 

Here's how I'm parsing the code atm:

 

$bodytext = stripslashes($a["post"]);
$bodytext = substr($bodytext, 0, 500);
$bodytext = "$bodytext...";
$bodytext = preg_replace("/\n/", "<br />", $bodytext);

  • Author

You could just use explode() and set the delimiter to be your <!-- more -->

 

would that look anything like this:

 

$display = explode("<!-- more -->", $bodytext);
$bodytext = $display[0];

Look on php.net/substr people have posted fairly useful functions for this very problem.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.