473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

remove from a string

Is there a function in PHP that will remove a blob from inside a
string. Similar to the substr() function, but instead of giving me the
string I want it to remove the string.

For example, I have the string "john goes running" I want to be able
to tell it to remove 5 characters starting at position 4, which would
get me "john running"

Thanks,

Aug 25 '05 #1
4 19008

werdna.si...@gmail.com wrote:
Is there a function in PHP that will remove a blob from inside a
string. Similar to the substr() function, but instead of giving me the
string I want it to remove the string.

For example, I have the string "john goes running" I want to be able
to tell it to remove 5 characters starting at position 4, which would
get me "john running"


You could combine str_replace and substr:

$str = 'john goes running';
echo str_replace(substr($str,4,5),'',$str);

Ken

Aug 25 '05 #2

we**********@gmail.com wrote:
Is there a function in PHP that will remove a blob from inside a
string. Similar to the substr() function, but instead of giving me the
string I want it to remove the string.

For example, I have the string "john goes running" I want to be able
to tell it to remove 5 characters starting at position 4, which would
get me "john running"


Check out str_replace()
http://us3.php.net/manual/en/function.str-replace.php

Aug 26 '05 #3
But then you end up replacing every instance of the substring should it
appears more than once. Better to just glue the two remaining ends
together:

substr($s, 0, 4) . substr($s, 4 + 5);

Aug 26 '05 #4
Chung Leong wrote:
But then you end up replacing every instance of the substring should it
appears more than once. Better to just glue the two remaining ends
together:

substr($s, 0, 4) . substr($s, 4 + 5);


There's another function that can be used if you want to replace only
one sub string, substr_replace(). See
<http://www.php.net/substr_replace>

Example:

<?
$str = 'john goes running and then goes to the store';
echo 'Original string: ' . $str . '<br>';
echo 'Using str_replace: ' .
str_replace(substr($str,4,5),'',$str).'<br>';
echo 'Using substr_replace: ' . substr_replace($str,'',4,5);
?>

Results:

Original string: john goes running and then goes to the store
Using str_replace: john running and then to the store
Using substr_replace: john running and then goes to the store

Ken

Aug 26 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christopher Armstrong | last post by:
Hello! I'm trying to write a part of a program that will remove all files in its directory. I have tried the std::remove feature of the standard library, but I don't know its syntax. Also, what's...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
4
by: u7djo | last post by:
Hi, I'm currently building an application in Access and as part of this need to import forms and modules from another database. Some of the imports will be revisions of existing forms/modules so I...
1
by: Craig Buchanan | last post by:
what is the fastest way to remove a value from a string array? something like: dim x as string() = {"A","B","C","D"} 'remove C x.Clear(x, x.IndexOf(x, "C"), 1) Questions:
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
10
by: Mike Copeland | last post by:
I have data I need to normalize - it's "name" data. For example, I have the following: "Watts, J.C." I wish to (1) parse the "first name" ("J.C.") and adjust it to "JC". Essentially, I want to...
26
by: Brad | last post by:
I'm writing a function to remove certain characters from strings. For example, I often get strings with commas... they look like this: "12,384" I'd like to take that string, remove the comma...
10
by: Tony Johansson | last post by:
Hello! I have a collection with a lot of object. Each object has the following definition. public class ParametermappingObj { private string Name {get;set;} private string Id {get;set;}...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.