Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

preg replace

General discussions related to php

Moderators: macek, egami, gesf

preg replace

Postby WangLi » Thu Aug 02, 2012 3:32 am

Hello, i'm trying to write a simple script to replace all ascii codes in a string into their char value. Here's the code i wrote:

Code: Select all

<?php
$string = " I&#39;m a string ";
$pattern = "/&#(\d\d);/";
$replacement = chr("$1");
echo preg_replace($pattern, $replacement, $string); 
?>


I think that in the replacement slot is not possible to use chr("$1") even if:
1) with $replacement = chr(39) preg_replace correctly returns the apostrophe
2) with $replacement = $1 preg_replace correctly returns "39"

how can i solve it ?

Thanks for you help
WangLi
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Aug 02, 2012 3:25 am

Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.