mcfcben Posted March 16, 2010 Share Posted March 16, 2010 Hi guys, I'm currently working on a piece of code, where I'm aiming to strip special characters such as '.' and '-', leaving just numbers and letters format, this data needs to be exported to a csv file and held there. I've researched preg_replace and decided to use it, and found that the code I created did work when random text/characters was used in the $input array and an echo on the page was tested $input .="c.products_model"; $output = preg_replace("/[^a-zA-Z0-9\s]/","",$input); (in the above code, c.products_model is relating to the database field I need to call and modify, then be shown in the csv file with special characters stripped out) the SQL query I'm using to export the data to csv is structured like this: - i dont think this is where the issue lies but thought i'd include it just in case $sql_query = "SELECT concat( '" . $productURL . "' ,b.products_id) AS product_url, a.manufacturers_name, c.products_model, $output AS products_model_2 from $table WHERE a.manufacturers_id = c.manufacturers_id AND b.products_id = c.products_id AND $wherecond ORDER BY $ordersort"; Where am I going wrong here? I've tried a few workarounds and I'm postive the issue is regarding $input as the actual preg_replace code ive called does work when i change the input variable Link to comment https://forums.phpfreaks.com/topic/195428-stripping-special-characters-from-a-database-field-for-csv/ Share on other sites More sharing options...
mcfcben Posted March 16, 2010 Author Share Posted March 16, 2010 been tweaking this more, and now ive got it working with csv a bit better my main problem is that preg_replace refuses to recognise that im trying to pass a table field to be edited, not a string (it strips c.products_model of the . and _ which is great as it shows the preg_replace actually works... but i want c.products_model to be called and the data within this field to be stripped... :/) its probably a really basic fix, but im stumped! Link to comment https://forums.phpfreaks.com/topic/195428-stripping-special-characters-from-a-database-field-for-csv/#findComment-1027025 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.