Jump to content

[SOLVED] Parse string from the middle of a string


refiking

Recommended Posts

You mean delete everything before or after (like you said) Or delete everything within those 2 variables, like you demonstrated?

 

$string = "12345"
$section1 = 12;
$section2 = 4;
$newstring = str_replace(Array($section1, $section2), NULL, $string);
echo $newstring; // 35

<?php
$string = "012333456";
$section1 = '12';
$section2 = '4';
$start = strpos($string,$section1)+strlen($section1);
$end = strpos($string,$section2,$start);
$newstring = substr($string,$start,$end-$start);
echo $newstring; // 3

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.