Newbie - Need to program something simple, where shall I start?

Discussion in 'PHP' started by Ashkan, Jul 1, 2007.

  1. #1
    Ok. I need to program something that does this:

    ----------------
    1. First I have text file or data base full of 11 digit random numbers like : 48928444123, 82938412345,12682839427, etc

    2. I need to assign letters to each number. Imagine each number corresponds to a set of letters forexample:
    1 = A, B
    2 = C, D
    3 = E, F

    3. Now I need to create a program such that when people search for a word, the word is converted into numbers and then a search for these digits is carried out within the numbers in the text file.

    (Forexample a person searches for the word : "ACE", going by the corresponding numbers in step two this becomes "123". Then the program looks through the numbers in the text file to find 11 digit numbers which contain "123" and gives out the results: e.g. 48928323123, 82938412345)

    4. I then need the program to replace "123" in those numbers with the searched word(i.e. "ACE"). e.g. 48928323ACE, 829384ACE45

    ----------------

    is this easy to program? where is the best place to start?

    Thanks in advance!
     
    Ashkan, Jul 1, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    the only problem is that using the same number twice and numbers reaching double digits it would be hard to switch back. but to do your example...

    
    <?php
    	$_n = array(
    			"a" => 1,
    			"b" => 1,
    			"c" => 2,
    			"d" => 2,
    			"e" => 3,
    			"f" => 3,
    			"g" => 4,
    			"h" => 4,
    			"i" => 5,
    			"j" => 5,
    			"k" => 6,
    			"l" => 6,
    			"m" => 7,
    			"n" => 7,
    			"o" => 8,
    			"p" => 8,
    			"q" => 9,
    			"r" => 9,
    			"s" => 10,
    			"t" => 10,
    			"u" => 11,
    			"v" => 11,
    			"w" => 12,
    			"x" => 12,
    			"y" => 13,
    			"z" => 13
    		);
    	
    	function make_num($str)
    	{
    		global $_n;
    
    		$r = "";
    		for($x=0; $x<=strlen($str)-1; $x++)
    			$r .= $_n[strtolower($str[$x])];
    
    		return $r;
    	}
    
    	function revert_num($num)
    	{
    		global $_n;
    
    		$r = "";
    		for($x=0; $x<=strlen($num)-1; $x++)
    			$r .= strtoupper(array_search($num[$x],$_n));
    
    		return $r;
    
    	}
    	echo make_num("ACE"). " = " .revert_num(make_num("ACE"));
    ?>
    
    PHP:
    though try this and see what you get.

    
    echo make_num("ANSIMATION"). " = " .revert_num(make_num("ANSIMATION"));
    
    PHP:
     
    ansi, Jul 1, 2007 IP
  3. Ashkan

    Ashkan Active Member

    Messages:
    117
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks, I'm going to find some simple to tutorials to see where and how to run the php program etc and some of the basics and then look at the code you have sent.

    Are there any popular php tutorial website?
     
    Ashkan, Jul 1, 2007 IP