How to add multi words?

Discussion in 'PHP' started by a4tech, Apr 3, 2013.

  1. #1
    Hello, I am wanted to add multi words in ($title, $description, $tags) for scan $flag. How can I add them in the below script to check the flag function.

    <?php
    $flag = '/test/i';
    $content = '<h1>Page Title</h1>
    <p>test world.</p>';
    if(!preg_match($flag, $content)) {
      echo $content;
    } else{
    }
    ?>
    PHP:

    Thank You.
     
    Last edited: Apr 3, 2013
    a4tech, Apr 3, 2013 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    I've already sent you the solution, let me know if it worked.
     
    HuggyStudios, Apr 3, 2013 IP
    ugod likes this.
  3. usr

    usr Greenhorn

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #3
    It seems that preg_match doesn't work unless the pattern is written as a constant/text, so I suggest using another page with the pattern as a text, not a variable:


    //eg
    $array_flags=array('flag1','flag2','flag3');

    $array_content=array('content1','content2','content3',);

    for($i=0;$i<count=array($array_flags);$i++)

    {
    //for a more simple notation

    $y=$array_flags[$i];

    create preg_match with the pattern written as a 'text' to be put on a page (function,php)

    $a1="<?php

    function look4match(";
    $a2='$y';
    $a3=")
    {

    if(preg_match('/";
    $a4=$x;
    $a5="/',";
    $a6='$y';
    $a7="))
    {
    ";
    $a8='$val';
    $a9="=1;
    }
    else
    {
    ";
    $a10='$val';
    $a11="=0;
    }
    return ";
    $a12='$val';
    $a13=";
    }
    ?>";
    $a="$a1$a2$a3$a4$a5$a6$a7$a8$a9$a10$a11$a12$a13";


    //create the page
    file_put_contents('function.php',$a);
    include('function.php');

    //use the text which has to be matched with $array_flags[$i]

    for($j=0;$j<count($array_content); $j++)

    {

    $val=look4match($array_content[$j]);

    }

    }
     
    usr, Apr 9, 2013 IP
    ugod likes this.
  4. DzignStudios

    DzignStudios Greenhorn

    Messages:
    13
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    23
    #4
    I can help you on this, let me know if it dint worked.
     
    DzignStudios, Apr 9, 2013 IP
    ugod likes this.
  5. usr

    usr Greenhorn

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #5
    I made this functionon in order to be able to use preg_match in this form ( preg_match('/$pattern/',$text) so, when I copied and put it in loop for you I change wrong var. Sorry



    $a4 is actually $array_flags[$i] {the pattern)
    and $y is $array_content[$j] (the text to be checked

    $orry, again
    -------------
    the function is:

    function look4match($y)
    {
    if(preg_match('/pattern/',$y)) //where 'pattern' is $array_flags[$i]
    {
    $val=1;
    }
    else
    {
    $val=0;
    }
    return$val;
    }
    ---
    in order to print/echo $array_flags[$i] as a pattern/text, write it on another page, 'function.php' with file_put_contents() and $a as text;

    function.php looks like this
    <?php

    function look4match($y)
    {
    if(preg_match('/pattern/',$y)) //where 'pattern' is $array_flags[$i] or $a4 as a text
    {
    $val=1;
    }
    else
    {
    $val=0;
    }
    return$val;
    }
    ?>
    ---
    use include() to be able to aply the function
    -----------------------------------

    It seems that preg_match doesn't work unless the pattern is written as a constant/text, so I suggest using another page with the pattern as a text, not a variable:

    //eg
    $array_flags=array('flag1','flag2','flag3');

    $array_content=array('content1','content2','content3',);

    for($i=0;$i<count=array($array_flags);$i++)

    {
    //for a more simple notation

    $y=$array_flags[$i];

    create preg_match with the pattern written as a 'text' to be put on a page (function,php)

    $a1="<?php

    function look4match(";
    $a2='$y';
    $a3=")
    {

    if(preg_match('/";

    $a4=$array_flags[$i];

    $a5="/',";
    $a6='$y';
    $a7="))
    {
    ";
    $a8='$val';
    $a9="=1;
    }
    else
    {
    ";
    $a10='$val';
    $a11="=0;
    }
    return ";
    $a12='$val';
    $a13=";
    }
    ?>";
    $a="$a1$a2$a3$a4$a5$a6$a7$a8$a9$a10$a11$a12$a13";


    //create the page
    file_put_contents('function.php',$a);
    include('function.php');

    //use the text which has to be matched with $array_flags[$i]

    for($j=0;$j<count($array_content); $j++)

    {

    $val=look4match($array_content[$j]);

    if($val==1)
    {
    then it matches
    }

    }

    }
     
    usr, Apr 10, 2013 IP