Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 26th, 2012, 05:20 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Location: IIT MADRAS,CHENNAI ,INDIA
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?
Reply With Quote
  #2 (permalink)  
Old February 27th, 2012, 06:47 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
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;
}

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.