slashpine Posted September 18, 2006 Share Posted September 18, 2006 I am guessing this "preg_replace" is the best option in this?using the code below ( see post)http://www.phpfreaks.com/forums/index.php/topic,106136.0.html many of the addresses (addr1) have a # followed by either a letter or a number i.e., # A , # 400 etc. etc.Can I use preg_replace? so the scritp ignores the # and everything following it in that column ?[code] $url = "http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr="; $url.= str_replace(" ","+",$query_data['addr1']); $url.= "&csz="; $url1 = str_replace(",","%2C",$query_data['addr2']); $url.= str_replace(" ","+",$url1). "&country=us"; echo "<a href='". $url. "'><img src='images/maplink.gif' width='89' height='17' alt=''/></a>";[/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted September 18, 2006 Share Posted September 18, 2006 [tt]preg_replace('/#.*$/', '', $variable);[/tt] Quote Link to comment Share on other sites More sharing options...
slashpine Posted September 18, 2006 Author Share Posted September 18, 2006 sorry for the wrong placement...the script ignores the line... no errors but the # and what follows prevent the script from working? Quote Link to comment Share on other sites More sharing options...
effigy Posted September 18, 2006 Share Posted September 18, 2006 What does your code look like? Quote Link to comment Share on other sites More sharing options...
slashpine Posted September 18, 2006 Author Share Posted September 18, 2006 [code]$url = "http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr="; $url = "http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr="; $url.= str_replace(" ","+",$row['address']); $url.= "&csz="; $url1 = str_replace(",","%2C",$row['city']); $url.= str_replace(" ","+",$url1). ",GA+&country=us";[/code]this is edited from the code in the original in thread I cited for my column names/queryThis works great as long as there is no # A or # 800 etc after the street address ($address) Quote Link to comment Share on other sites More sharing options...
effigy Posted September 18, 2006 Share Posted September 18, 2006 I don't see the preg_replace in your code--how are you using it? Quote Link to comment Share on other sites More sharing options...
slashpine Posted September 18, 2006 Author Share Posted September 18, 2006 $url.= preg_replace('/#.*$/', '', $row['address']); Quote Link to comment Share on other sites More sharing options...
effigy Posted September 19, 2006 Share Posted September 19, 2006 Works for me:[code]<pre><?php $row = array( address => '123 Main St. #4' ); echo $url.= preg_replace('/#.*$/', '', $row['address']);?></pre>[/code] Quote Link to comment Share on other sites More sharing options...
slashpine Posted September 19, 2006 Author Share Posted September 19, 2006 thanks for the reply but I don't see how to apply that to the code cited...the script parses the "address" from the database and builds a URL that displays a map from Yahoocan you expand on how I can emply this or possibly suggest another way of eliminating the problem of the # and what follows...?Thanks again...[edited]I solved this problem by changing the "#" character in the table column to the word "Unit" this allows the the script tpo parse the correct address into the URL (script)Thanks again for all the help... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.