Microsoft
Software
Hardware
Network
Question : PHP: Find and Replace only 1st occurance
I want PHP to go through my string and only replace the first occurrence of the words I want replaced. str_replace seems to replace every occurrence, I just want to have the 1st occurrence replaced. How can I go about doing this?
Answer : PHP: Find and Replace only 1st occurance
Use preg_replace ...here is an example..
<?
$var = 'abcdef abcdef abcdef';
// pattern, replacement, string, limit
echo preg_replace('/abc/', '123', $var, 1); // outputs '123def abcdef abcdef'
?>
Random Solutions
How can i add column name in list generic?
Symantec Antivirus 9.0.0.338 move to a new server issues!
Use .NET or SSIS to download Exhange email and process attachments
How can I reference information from one sheet to another by values selected in a drop down menu
VMware Workstation 7.1 Won't Install
How can I find the position of the first occurance of a numeric charater in a string with PHP?
Should I make a Drupal Theme from scratch?
Does OpenOffice allow Windows 7 preview pane to preview .doc and .xls files?
gss_acquire_cred failed unspecified gss failure : Apache
How do I update my tables in mysql to include new data?