How can I get some part of $B to be only auto(The first word in $A[1])?

if(preg_match('/^(.*)">(.*)/',$A[1],$B) == 1)
{
    die($B[1]);
}

$A[1] is....
auto">auto</a>, <a href="automobile">automobile</a>, <a href="motorcar">motorcar</a>, <a href="machine">machine</a></div><div class=Rel><a hr .................................... /tr><tr><td><a href="zw

Have a look at the non-greedy query modifyer, the question mark ?.

if(preg_match('/^((.*)">)?(.*?)</',$A[1],$B) == 1)
  die($B[3]);

That still returns the result zw and I want it to return the result of auto!

How do I stop preg match when it reaches a certain character.
For example this text string...

auto">auto,

I want to just get auto? how do I do that? I want to basically stop at ">

As I said before, use the non-greedy modifier.
I forgot the ? after the first pattern.

<?php

$A[1] = 'auto">auto</a>, <a href="automobile">automobile</a>, <a href="motorcar">motorcar</a>, <a href="machine">machine</a></div><div class=Rel><a hr .................................... /tr><tr><td><a href="zw' ;

      if(preg_match('/^((.*?)">)?(.*?)</',$A[1],$B) == 1)
	      die($B[3]);
// result: auto

Alright thanks. New question though...

This code I built is suppose to build a dictionary. Yet some words continue to get caught up over and over again during the mysql insert query. How can I do this and add words to my MySQL dictionary? I want this to be a recurring process where new words will be added to my dictionary automatically?

<?php

session_start();

$connect = mysql_connect("127.0.0.1","root","");

if (!$connect)
  {
  die("MySQL could not connect!");
  }

$DB = mysql_select_db('autoblogging');

if(!$DB)
{
die("MySQL could not select Database!");
}

if(isset($_SESSION['word']))
{
    $Word = $_SESSION['word'];
}
else
{
    $_SESSION['word'] = "car";
    $Word = $_SESSION['word'];
}

$URL = "http://www.thefreedictionary.com/$Word";

$open = fopen($URL,"r");

while(! feof($open))
{
    $Line = fgets($open);
    
    if(preg_match('/Rel><a href="(.*)">(.*)<\/a>/',$Line,$Z) == 1)
    {
        if(preg_match('/\S+/',$Z[1],$Y) == 1)
        {
            if(preg_match('/(.*)("+)/',$Y[0],$R) == 1)
            {
                
            }
        }
    }
    
    //-------------------------------------------------------------
    
    if(preg_match('/Syn><a href="(.*)">(.*)<\/a>/',$Line,$A) == 1)
    {
        if(preg_match('/\S+/',$A[1],$B) == 1)
        {
            if(preg_match('/(.*)("+)/',$B[0],$C) == 1)
            {
                
            }
        }
    }
}

$Abc = $C[1];
$Abc = $R[1];

$Exists_Query = mysql_query("SELECT * FROM Dictionary WHERE word='$Abc'");
$Exists_Query2 = mysql_query("SELECT * FROM Dictionary WHERE word='$Abc2'");

die(mysql_num_rows($Exists_Query).mysql_num_rows($Exists_Query2)."----$Abc");

if(mysql_num_rows($Exists_Query) == 0 || mysql_num_rows($Exists_Query2) == 0)
{
    if(strpos($C[1],"+") != FALSE)
    {
        $New_Word = str_ireplace("+"," ",$C[1]);
    }
    else
    {
        $New_Word = $C[1];
    }
    
        if(strpos($R[1],"+") != FALSE)
    {
        $New_Word2 = str_ireplace("+"," ",$R[1]);
    }
    else
    {
        $New_Word2 = $R[1];
    }
    
    $Insert = mysql_query("INSERT INTO dictionary (word,s1,s2)
                           VALUES ('$Word','$New_Word','$New_Word2')");
    
    if(!$Insert)
    {
        die(mysql_error());
    }
    
    $_SESSION['word'] = $R[1];
    
}
else
{
    die($_SESSION['word'] = $C[1]);
}



header("LOCATION: builddictionary.php");

?>

For a new question, open a new thread and mark this as solved.
How do "words continue to get caught up over and over again during the mysql insert query" - what does that mean? How do you catch words? If you want to protect against double entries, add a unique index to your word field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.