function myFrequency($sentence)
{
    $words = myExplode($sentence);
    $frequency = array(" ");
    $i = 0;
    $count = count($words);
    foreach ($words as $word) {
        if (array_key_exists($word, $frequency)) {
            $frequency[$word]++;
        } else {
            $frequency[$word] = 1;
        }
    }
    /* foreach ($frequency as $key => $value) {
            echo "$key=>$value";
    
        }*/
    return $frequency;
}
Ejemplo n.º 2
0
<?php

include 'functions.php';
$myPointer = fopen("sentence.txt", "r");
$sentence = fread($myPointer, filesize("sentence.txt"));
$words = myExplode($sentence);
print_r($words);
$freq = myFreq($words);
echo "<br>";
echo "<pre>";
print_r($freq);
echo "</pre>";
function myNumber($number)
{
    return $number + 8;
}
$offset = myNumber(0);
echo $offset;
Ejemplo n.º 3
0
 function MyExplode()
 {
     return myExplode($this->string);
 }
<html>
	<?php 
include "C:/xampp/htdocs/xampp/Training/php/MyFunction/only_explode_function.php";
include "C:/xampp/htdocs/xampp/Training/php/Day20/OOP/stack_oop.php";
include "C:/xampp/htdocs/xampp/Training/php/MyFunction/calculator_function.php";
if (isset($_GET['string'])) {
    $expression = $_GET['string'];
    //$result = strLength($string);
    //echo $result;
    //$expression = "3 4 6 * -";
    $expArr = myExplode($expression);
    //print_r($expArr);
    $myStack = new Stack();
    foreach ($expArr as $op) {
        $temp = intval($op);
        //echo $temp;
        if ($temp) {
            $myStack->push($temp);
        } else {
            $op2 = $myStack->pop();
            $op1 = $myStack->pop();
            $result = calculator($op1, $op2, $op);
            //echo $result;
            $myStack->push($result);
        }
    }
    echo "My result is ", $myStack->pop();
}
?>
	<body>
		<form action="postfix_with_oop.php" method="get" align="center">
Ejemplo n.º 5
0
 function explode1()
 {
     return myExplode($this->string);
 }
Ejemplo n.º 6
0
 function setExplode($sentence)
 {
     $result = myExplode($sentence);
     $this->word = $result;
     return $this->word;
 }
Ejemplo n.º 7
0
function myExplode($delim, $myString)
{
    //declaring function/user declared
    $retval = array(" ");
    //code that needs to be executed
    $currWord = " ";
    //variable is to remember the current word//currentindex++ is the cursor moving from space to space.
    for ($currentindex = 0; $currentindex < strlen($myString); $currentindex++) {
        //executing my code - currentindex is my pointer to where i am in the string//then evaluates the loop seeing if it is true, so the loop continues, if not the loop stops and moves on//currentindex++ is the increment counter-telling it to add one after every loop.
        if ($myString[$currentindex] == " ") {
            //if evaluates whether the character is a space or not
            array_push($retval, $currWord);
            // saving the word-gets pushed into an array
            $currWord = " ";
            //emptying
        } else {
            $currWord = $currWord . $myString[$currentindex];
            //builds word one character at a time
        }
    }
    //else tells if the code is untrue and stops the loop
    array_push($retval, $currWord);
    //pushing the variables onto the end
    return $retval;
    //return immediately ends the whole function
}
print_r(myExplode(" ", "the car has a top speed of 100"));
?>