PHParadise source code of “string replace” in category “string handling”
PHParadise
>
string handling
> string replace
some useful functions to replace strings in strings
back to the download options
see PHP code for “string replace”
see demo of “string replace”
copy the code of string handling / string replace
click here to select all the code
<?php /*------------------------------------------------------------------------------ | | PHParadise source code | |------------------------------------------------------------------------------- | | file: string replace | category: string handling | | last modified: Mon, 20 Jun 2005 16:41:17 GMT | downloaded: Fri, 25 May 2012 03:12:27 GMT as copy from textarea | | code URL: | http://phparadise.de/php-code/string-handling/string-replace/ | | description: | some useful functions to replace strings in strings | ------------------------------------------------------------------------------*/ // Multiple string replace // expects an array with $string => $replacement $old_string = 'file_example.txt<br>another_file.txt<br>phpexample.php<br>'; $replacements = array('_'=>' ','<br>'=>' ,','.txt'=>' (Text)','.php'=>' (PHP)'); $new_string = strtr($old_string,$replacements); echo '<p>'.$new_string.'</p>'; // Number Padding, PHP // Doesn't have to be zeros or numberic but handy for making sure you keep leading zeros on // day and month values when receiving such values as POST or GET variables. $no_a = 3; $no_a = str_pad($no_a, 2, '0', STR_PAD_LEFT); echo '<p>'.$no_a.'</p>'; // String replacing, PHP $old_string = 'the qick brown fox jumped over the lazy dog.'; $new_string = str_replace('qick brown fox', 'slow black bear', $old_string); echo '<p>'.$new_string.'</p>'; // Remove tags using preg_replace, PHP // This should remove anything and everything everything between // 'less than' and 'greater than' characters $source_string = '<b>bold</b> <a href="blank.php">link</a>'; $replacement = '(tag removed)'; $replaced_string = preg_replace('[<.*?.>]', $replacement, $source_string); echo '<p>'.$replaced_string.'</p>'; // preg_replace can be used with arrays as well $string = 'The quick brown fox jumped over the lazy dog.'; $patterns = array('/quick/','/brown/','/fox/'); $replacements = array('slow','black','bear'); echo '<p>'.preg_replace($patterns, $replacements, $string).'</p>'; ?>
array handling
array multi sort
entries per row
complex array sort
communication
send email
databases
mySQL class
mySQL to excel
date and time
date and time
date examples
loading time
remote last modified
timestamp to time passed
directories
directory list with exec
htaccess 2
htaccess
human readable size
read dir and list
recursive directory delete
recursive directory listing
recursive make directory
directory structure to list
file handling
delete file
download counter
file exists
file informations
file upload
include secure
line by line
open file
read and select csv
read file
strip file extension
write to file
write to first line of file
forms
datepicker
google results
keep selected combobox
simple calculator
html and code
alternate row colors
convert html
extract vars
floating div
force PHP in HTML
get offsite code
html entities
html head
meta tags
prime numbers
simple bar chart
simple php code highlight
view php source
image editing
analog GD clock
colorizing
crop image
grayscale an image
image rotate
outlining
shadowing
textures
translucent text
invert image
image handling
base64 image encode
image upload and resize
list image folder
resize offsite image
information
detect user language
domaincheck
google position
phpinfo
referer info
server variables
visitor IP
visitors online
sessions and co
basic authorization
sessions class
string handling
autolink
extract string from offsite
insert at specific location
number to words
string compare
string in string
string replace
string to columns
substring examples
summarize article