Jump to content

Archived

This topic is now archived and is closed to further replies.

slashpine

help with preg_replace ?

Recommended Posts

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]

Share this post


Link to post
Share on other sites
sorry for the wrong placement...

the script ignores the line... no errors but the # and what follows prevent the script from working

?

Share this post


Link to post
Share on other sites
[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.= "&amp;csz=";
    $url1 = str_replace(",","%2C",$row['city']);
    $url.= str_replace(" ","+",$url1). ",GA+&amp;country=us";[/code]

this is edited from the  code in the original in thread I cited for my column names/query

This works great as long as there is no # A or # 800  etc after the street address ($address)

Share this post


Link to post
Share on other sites
I don't see the preg_replace in your code--how are you using it?

Share this post


Link to post
Share on other sites
Works for me:

[code]
<pre>
<?php

$row = array(
address => '123 Main St. #4'
);
echo $url.= preg_replace('/#.*$/', '', $row['address']);

?>
</pre>
[/code]

Share this post


Link to post
Share on other sites
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 Yahoo

can 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...

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.