preg_replace problem ((Solved))

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 986 Views - Last Post: 05 October 2009 - 05:18 AM Rate Topic: -----

#1 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

preg_replace problem ((Solved))

Posted 04 October 2009 - 05:30 AM

hi PHP experts,

i want to change English Number to Dari (Persian) number, i have this code it gives me an error
atal error: Call to undefined function af_nubmer() in D:\wamp\www\...

here is my code and i am using HTML special characters.
function af_nubers($number){
	$AF = array(
				'۰',
				"۱",
				"۲",
				"۳",
				"۴",
				"۵",
				"۶",
				"۷",
				"۸",
				"۹"
				);
	
	$US = array(
				"0",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9"
				);
	
	return preg_replace($AF,$US);				
}


or if I am going to wrong way please redirect me to right way :)

Thanks in advance :)

Edit:

the $AF array contain these characters without slashes :)
'\&\#\1776;',
"\&\#\1777;",
"\&\#\1778;",
"\&\#\1779;",
"\&\#\1780;",
"\&\#\1781;",
"\&\#\1782;",
"\&\#\1783;",
"\&\#\1784;",
"\&\#\1785;"

This post has been edited by noorahmad: 05 October 2009 - 05:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: preg_replace problem ((Solved))

#2 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 04 October 2009 - 05:38 AM

dont you need this
return preg_replace($AF,$US,$number);



tommyflint
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3105
  • View blog
  • Posts: 10,905
  • Joined: 08-August 08

Re: preg_replace problem ((Solved))

Posted 04 October 2009 - 07:13 AM

af_nubers != af_nubmer
Was This Post Helpful? 1
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 04 October 2009 - 08:46 PM

thanks CT and tomy, that was not my problem, i was in hurry and didn't read the topic :D

my real problem is in preg_replace it gives me this error
Warning: preg_replace() [function.preg-replace]: No ending delimiter '&' found in D:\wamp...


function af_numbers($number){
	$AF = array(
				'۰',
				"۱",
				"۲",
				"۳",
				"۴",
				"۵",
				"۶",
				"۷",
				"۸",
				"۹"
				);
	
	$US = array(
				"0",
				"2",
				"3",
				"4",
				"5",
				"6",
				"7",
				"8",
				"9"
				);
	
	return preg_replace($AF,$US,$number);				
}
echo af_numbers("0010101");


any help :)

This post has been edited by noorahmad: 04 October 2009 - 08:48 PM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3105
  • View blog
  • Posts: 10,905
  • Joined: 08-August 08

Re: preg_replace problem ((Solved))

Posted 04 October 2009 - 08:50 PM

Try using str_replace instead. It's designed for what you're trying to do.
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 04 October 2009 - 09:03 PM

I tried str_replace but it gives me this error 1۷2;۷2;۷2;۷1;;1۷2;۷2;۷2;۷1;; and then i used preg_replace function :)
Was This Post Helpful? 0
  • +
  • -

#7 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 01:46 AM

try this
function af_numbers($number){
		$AF = array(
								'۰',
								"۱",
								"۲",
								"۳",
								"۴",
								"۵",
								"۶",
								"۷",
								"۸",
								"۹"
								);
		
		$US = array(
								"0",
								"1",
								"2",
								"3",
								"4",
								"5",
								"6",
								"7",
								"8",
								"9"
								);
		
		return str_replace($US,$AF,$number);
}



tommyflint
Was This Post Helpful? 1
  • +
  • -

#8 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 02:21 AM

@tommyflint: I tried, but i am getting same error :(
Was This Post Helpful? 0
  • +
  • -

#9 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 02:22 AM

that's weird it's working fine for me
when using this code it works fine:

<?php
$number = 0;
function af_numbers($number){
		$AF = array(
								'۰',
								"۱",
								"۲",
								"۳",
								"۴",
								"۵",
								"۶",
								"۷",
								"۸",
								"۹"
								);
		
		$US = array(
								"0",
								"1",
								"2",
								"3",
								"4",
								"5",
								"6",
								"7",
								"8",
								"9"
								);
		
		return str_replace($US,$AF,$number);
}

$new = af_numbers($number);
echo $new;
?>



tommyflint
Was This Post Helpful? 0
  • +
  • -

#10 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 02:29 AM

are you using HTML codes in your array "\&\#1777;", Without slashes? or simply ۱۲۳۴۵۶۷۸۹ :)
Was This Post Helpful? 0
  • +
  • -

#11 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 02:30 AM

i was simply using ۱۲۳۴۵۶۷۸۹
Was This Post Helpful? 0
  • +
  • -

#12 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 03:05 AM

I have found it script that will do this if you want it'?

tommyflint
Was This Post Helpful? 0
  • +
  • -

#13 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 03:17 AM

Quote

I have found it script that will do this if you want it'?


Then what are you waiting for...
Was This Post Helpful? 0
  • +
  • -

#14 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 03:39 AM

Attached File  NumPer.zip (1.91K)
Number of downloads: 48
Was This Post Helpful? 1
  • +
  • -

#15 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: preg_replace problem ((Solved))

Posted 05 October 2009 - 04:24 AM

thanks tommy, this is not what i want. :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2