John Davidson

PHP Delete an entire string from the beginning of a word

0 comments
Message:


I need to delete all the string type content that is from the beginning of a word, I give you an example



Lorem Ipsum is simply the dummy text of printers and text files. Lorem Ipsum has been the industry's standard dummy text since the 1500s, when an unknown printer used a gallery of type and mixed it up in such a way that he managed to make a specimen textbook. Not only did it survive 500 years, but it also entered as a text of



I have to delete from unknown, including unknown, and the result should be the following



Lorem Ipsum is simply the dummy text of printers and text files. Lorem Ipsum has been the industry's standard dummy text since the 1500s, when an



thanks for al



My Answer:
You can achieve this by using the `substr` function in PHP. Here is an example code snippet to delete the string from the beginning of a word:

php
$string = "Lorem Ipsum is simply the dummy text of printers and text files. Lorem Ipsum has been the industry's standard dummy text since the 1500s, when an unknown printer used a gallery of type and mixed it up in such a way that he managed to make a specimen textbook. Not only did it survive 500 years, but it also entered as a text of";

$wordToDelete = "unknown";

$position = strpos($string, $wordToDelete);

if ($position !== false) {
$result = substr($string, 0, $position);
echo $result;
} else {
echo "Word not found in the string.";
}


This code will output:


Lorem Ipsum is simply the dummy text of printers and text files. Lorem Ipsum has been the industry's standard dummy text since the 1500s, when an

Rate this post

4 of 5 based on 8107 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us