Jump to content

Elements Mysteriously Dropping From Array - trouble with PREG_SPLIT & PREG_REPLACE


Greywacke
 Share

Recommended Posts

hi again...at the moment i am battling with the following piece of code:

function gettransactions($s) {    //= supplier id, >= from and <= to dates available create constraints    // ".(($numargs>0)?" WHERE ":"").join(" AND ",$arg_list)."    $arr = array();    if ($s > 0) {        array_push($arr,"13_prospectleadsent.bigint_SupplierID = ".$GLOBALS["s"]);    }    array_push($arr,"13_prospectleadsent.timestamp_Sent >= \"".$GLOBALS["f"]."\"");    array_push($arr,"13_prospectleadsent.timestamp_Sent <= \"".$GLOBALS["t"]."\"");    $tsql = "SELECT 10_serviceprospects.bigint_ProspectID, 13_prospectleadsent.smallint_ProspectOrdinal, 13_prospectleadsent.timestamp_Sent, 10_serviceprospects.text_LeadAttributes, 10_serviceprospects.text_Consumer, 1_regions.text_RegionDescription, 2_servicescatalogue.text_ServiceDescription FROM 13_prospectleadsent LEFT JOIN 10_serviceprospects ON (13_prospectleadsent.bigint_ProspectID = 10_serviceprospects.bigint_ProspectID) LEFT JOIN 1_regions ON (10_serviceprospects.bigint_RegionID = 1_regions.bigint_RegionID) LEFT JOIN 2_servicescatalogue ON (10_serviceprospects.bigint_ServiceID = 2_servicescatalogue.bigint_ServiceID) WHERE ".join(" AND ",$arr)." ORDER BY 13_prospectleadsent.timestamp_Sent DESC;";    $result = mysql_query_errors($tsql , $conn , __FILE__ , __LINE__ , false);    if ($result) {        while ($row = mysql_fetch_array($result)) {            $leadid = $row["bigint_ProspectID"];            $ordinal = $row["smallint_ProspectOrdinal"];            $ret .= "    <tr>\n";            $ret .= "        <td><div class=\"timestamps\">" . (($leadid>0)?"#".($leadid+9001100)."-".$ordinal."<br />":"") . $row["timestamp_Sent"] . "</div></td>\n";            $ret .= "        <td><div class=\"transactions\">";            $attr = [b]preg_split[/b]("/<[^>]+>/","//",[b]preg_replace[/b]("/[\r\n]+/","//",$row["text_LeadAttributes"]),-1,PREG_SPLIT_NO_EMPTY);            $attribsarr = array();            foreach ($attr as $key => $val) {                // contact name populate & supplier name in subject                // make/model style                // requirement & budget                // 3rde & 4de soos wat dit is                // $val = split(" = ",$value);                $attribsarr[$key] = $val;            }            $consumer = split(";",$row["text_Consumer"]);            $ret .= [color="#FF0000"]$attribsarr["products_description"][/color].[color="#FF8C00"]$attribsarr["vehicle_make_model"][/color].((strlen([color="#FF0000"]$attribsarr["products_description"][/color])==0)?" - ".[color="#FF8C00"]$attribsarr["canopy_style"][/color]:"")."<br />";            $ret .= [color="#FF0000"]$attribsarr["Requirement"][/color].[color="#FF8C00"]$attribsarr["canopy_req"][/color]." - ".[color="#FF0000"]$attribsarr["Budget"][/color].[color="#FF8C00"]$attribsarr["budget"][/color]."<br />";            $ret .= $consumer[0]." (".$consumer[1].", ".$consumer[2].")<br />".            $row["text_RegionDescription"]." (".$consumer[3].")";            $ret .= "</div></td>\n";            unset($attribsarr);        }        mysql_free_result($result);    }    return $ret;}

now the problem is that in the statement e-mails, sales leads with the following styles of attribute sets:

canopy_req = [color="#FF8C00"]new_white[/color]<br>canopy_style = [color="#FF8C00"]highline_standard[/color]<br>budget = [color="#FF8C00"]R3,000 to R4,000[/color]<br>fitment = [color="#FF8C00"]ASAP[/color]<br>vehicle_status = [color="#FF8C00"]possession_yes[/color]<br>vehicle_make_model = [color="#FF8C00"]Opel - Corsa[/color]<br>year_model = [color="#FF8C00"]2009[/color]

and

products_description = [color="#FF0000"]Tata D/C Canopy - Half Door[/color]<br>Bakkie model = [color="#FF0000"]2004 - current model[/color]<br>Requirement = [color="#FF0000"]New - White[/color]<br>Colour code = [color="#FF0000"]White Non-coded (standard)[/color]<br>Budget = [color="#FF0000"]R3,000 to R4,000[/color]<br>Fitment = [color="#FF0000"]ASAP[/color]

keep getting the colored attributes in bold - dropped from display:

Opel - Corsa - highline_standardnew_white - R3,000 to R4,000Jean Pitout (jean@jpassoc.co.za, 082-302-4516)Gauteng - Tshwane Metro (Bronkhorstspruit)
and
Tata D/C Canopy - Half DoorNew - White - R3,000 to R4,000Justin Funck (justin.funck@dhl.com, 0824655064)Gauteng - Ekurhuleni Metro (Boksburg)
unfortunately at the moment all the $attribsarr elements (red and orange from the various sources) are being dropped.it seems to be that my preg_replace and preg_split functions have regular expressions with unexpected results in this piece of code - for the life of me, i cannot figure out why this is happening. any assistance asap would be greatly appreciated, so this issue can be resolved before the end of the weekend please :)i need to remove all possible line breaks and carriage returns, before splitting the string by all html tags. or both xhtml 1.0 and html 4.0 line break tags. Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

ok generated a function now to convert the attributes into the array with named elements.

				$attribsarr = [color="#008000"][b]formattribs[/b][/color]($row1["text_LeadAttributes"]);				$consumer = split(";",$row1["text_Consumer"]);				$ret .= $attribsarr["products_description"].$attribsarr["vehicle_make_model"].((strlen($attribsarr["products_description"])==0)?" - ".$attribsarr["canopy_style"]:"")."<br />";				$ret .= $attribsarr["Requirement"].$attribsarr["canopy_req"]." - ".$attribsarr["Budget"].$attribsarr["budget"]."<br />";				$ret .= $consumer[0]." (".$consumer[1].", ".$consumer[2].")<br />".				$row1["text_RegionDescription"]." (".$consumer[3].")";				unset($attribsarr);

and

			$attribsarr = [color="#008000"][b]formattribs[/b][/color]($row["text_LeadAttributes"]);			$consumer = split(";",$row["text_Consumer"]);			$ret .= $attribsarr["products_description"].$attribsarr["vehicle_make_model"].((strlen($attribsarr["products_description"])==0)?" - ".$attribsarr["canopy_style"]:"")."<br />";			$ret .= $attribsarr["Requirement"].$attribsarr["canopy_req"]." - ".$attribsarr["Budget"].$attribsarr["budget"]."<br />";			$ret .= $consumer[0]." (".$consumer[1].", ".$consumer[2].")<br />".			$row["text_RegionDescription"]." (".$consumer[3].")";

now to test if it works :)

Edited by Pierre 'Greywacke' du Toit
Link to comment
Share on other sites

awesome ^^ this issue has now been resolved :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...