php - Using Regex (or anything) to do an advanced find and replace -


i'm trying find things inside double quotes , replace link using it. have on 500 lines of questions, don't want hand.

original php doc snippet:

$q2 = array ("what mars earth?", "what mars's position relative earth?");  $q3 = array ("what mars's surface like?", "show me view of surface of mars.", "show me picture of surface of mars."); 

formatting want:

$q2 = array ("<a href="answer.php?query=what+does+mars+look+like+from+earth%3f">what mars earth?</a>", <a href="answer.php?query=what+is+mars's+position+relative+to+earth%3f">"what mars's position relative earth?"); 

i tried using regex, without previous experience it, unsuccessful. using regexr (my example) came find of: "[a-za-z0-9\s.\?']*" , replace of: < href=answer.php?query=$&>$&"

this gave results like

$q2 = array (<a href=answer.php?query="what mars earth?">"what mars earth?"</a>", 

this close, not need. knows replace should use, or better program try. appreciated.

why not make function can pass array , array of links returned?

function make_questions_into_links($array) {     if (!is_array($array)) {         throw new exception('you did not pass array')     } else if (empty($array)) {         throw new exception('you passed empty array');     }      return array_map(function($element) {         return '<a href="answer.php?query=' . urlencode($element) . '">' . $element . '</a>';     }, $array); } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -