Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2012, 05:20 AM
Registered User
 
Join Date: Feb 2012
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Exclamation how to covert text string to other text string(i mean like langugae translation)

i use my own code language
i use
a = b
b = c
c = d
.....
z= a

then my "wrox.com" will be "xspy.dpy" ,how to write code in php for this?
 
Old February 27th, 2012, 06:47 AM
Friend of Wrox
 
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

One way to do it:
Code:
<?php

$strings = array('This is an example of encoding strings', 'wrox.com', 'really basic encoding');

foreach($strings as $string)
{
	echo 'String: ' . $string . '<br />';
	echo 'Encoded: ' . do_encode($string) . '<br /><br />';
}

$string = do_encode($strings[0]);
echo '<br /><br />';
echo 'String: ' . $strings[0] . '<br />';
echo 'Encoded: ' . $string . '<br />';
echo 'Decoded: ' . do_encode($string, true) . '<br />';


/*
* Encode the passed string
* passing 'true' as the second parameter will decode and encoded string
*/
function do_encode($string, $decode = false)
{
	$code = array();
	
	if( !sizeof($code) )
	{
		$a = range('a', 'z');
		$b = range('b', 'z');
		$b[] = 'a';

		if( !$decode )
		{
			$code = array_combine($a, $b);
		}
		else
		{
			$code = array_combine($b, $a);
		}
		unset($a, $b);
	}

	$return = '';
	for($i = 0, $i_end = strlen($string); $i < $i_end; $i++)
	{
		if( array_key_exists(substr($string, $i, 1), $code) )
		{
			$return .= $code[substr($string, $i, 1)];
		}
		else
		{
			$return .= substr($string, $i, 1);
		}
	}
	
	return $return;
}

?>
The Following User Says Thank You to UseLess For This Useful Post:
madhu131313 (February 28th, 2012)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Get a specific text from a string mrame XSLT 3 April 7th, 2009 07:03 AM
Parsing from a text string jroxit Classic ASP Basics 5 November 18th, 2008 05:08 PM
Text String to XML testsubject Visual Studio 2005 1 November 27th, 2006 06:26 AM
Text String to XML testsubject XML 1 November 26th, 2006 06:50 PM
How to Covert Excel to Text file as Database narendra_patil ASP.NET 1.x and 2.0 Application Design 1 July 20th, 2005 03:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.